Jump to content

How to kill players when is the last survivor?


Mario222

Recommended Posts

4 hours ago, Mario222 said:

I wanna kill a last survivor in DD or Fun maps before when is the last survivor like 2 seconds after but i don't know how to do it.

Maybe something like this?

local is_mode_running = false;
local kill_last_timer = false;

addEventHandler("onGamemodeMapStart", root,
    function(startedMap)
        -- Clean up from previous runtime.
        if (kill_last_timer) then
            killTimer(kill_last_timer);
            kill_last_timer = false;
        end
    
        is_mode_running = true;
        
        outputChatBox("started mode!");
    end
);

local function on_mode_end()
    outputChatBox("end of mode!");
end

local function on_last_survivor(survivor)
    kill_last_timer = setTimer(
        function()
            killPed( survivor );
            
            kill_last_timer = false;
        end, 2000, 1
    );
end

addEventHandler("onPlayerWasted", root,
    function()
        local alivePlayers = getAlivePlayers();
        
        if (is_mode_running) and (#alivePlayers <= 1) then
            is_mode_running = false;
            
            on_mode_end();
            
            if (#alivePlayers == 1) then
                on_last_survivor(alivePlayers[1]);
            end
        end
    end
);

 

  • Thanks 1
Link to comment
5 hours ago, The_GTA said:

Maybe something like this?

local is_mode_running = false;
local kill_last_timer = false;

addEventHandler("onGamemodeMapStart", root,
    function(startedMap)
        -- Clean up from previous runtime.
        if (kill_last_timer) then
            killTimer(kill_last_timer);
            kill_last_timer = false;
        end
    
        is_mode_running = true;
        
        outputChatBox("started mode!");
    end
);

local function on_mode_end()
    outputChatBox("end of mode!");
end

local function on_last_survivor(survivor)
    kill_last_timer = setTimer(
        function()
            killPed( survivor );
            
            kill_last_timer = false;
        end, 2000, 1
    );
end

addEventHandler("onPlayerWasted", root,
    function()
        local alivePlayers = getAlivePlayers();
        
        if (is_mode_running) and (#alivePlayers <= 1) then
            is_mode_running = false;
            
            on_mode_end();
            
            if (#alivePlayers == 1) then
                on_last_survivor(alivePlayers[1]);
            end
        end
    end
);

Oh thankyou very much! 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...