Jump to content

[SOLVED]


PaulDK

Recommended Posts

i want if i move suicide cancel then if the player not moved player would be kill or dead...

sorry for my bad english...

this is the script please help me Thanks in Advance dude's

local movestate = getPedMoveState (sourcePlayer)

function commitSuicide ( sourcePlayer )

outputChatBox("Dont Move to not cancel the suicide", sourcePlayer, 255, 255, 0, false)

if movestate then

outputChatBox("You have been moved the suicide will be cancel",sourcePlayer, 0, 0, 0, true)

zPlayer = getPlayerName(sourcePlayer)

if not movestate then

killPed ( sourcePlayer, sourcePlayer )

outputChatBox("You successfully suicide", sourcePlayer, 255, 255, 0, false)

end

end

end

addCommandHandler ( "kill", commitSuicide )

im waiting for your answers thanks in advance please help me :D

Edited by Guest
Link to comment
  • Moderators

Try this:

  
local timeBeforeSuicide = 5000 -- 5 seconds 
local suicideMoveCheckerTimer = 1000 -- 1 second 
function commitSuicide(thePlayer) 
    local px, py, pz = getElementPosition(thePlayer) --get the current position 
    local originPos = {x=px, y=py, z=pz} --store that pos in a table 
    setElementData(thePlayer, "originPos", originPos) --save it as an element data 
    local suicideTimer = setTimer(killPed, timeBeforeSuicide, 1, thePlayer, thePlayer) 
    setElementData(thePlayer, "suicideTimer", suicideTimer) 
    setTimer(suicidePosChecker, 1000, timeBeforeSuicide/1000, thePlayer) 
end 
addCommandHandler ( "kill", commitSuicide ) 
  
function suicidePosChecker(thePlayer) 
    local originPos = getElementData(thePlayer, "originPos") or {x=0, y=0, z=0} 
    local px, py, pz = getElementPosition(thePlayer) --get the new position 
    local distance = getDistanceBetweenPoints3D(px, py, pz, originPos.x, originPos.y, originPos.z) 
    if distance >= 2 then -- if the player moved at least 2 meters 
        local suicideTimer = getElementData(thePlayer, "suicideTimer") --get the timer 
        if suicideTimer then --if we got it, then  
            killTimer(suicideTimer) --kill it to prevent the suicide 
            outputChatBox("You moved and the suicide has been canceled !", thePlayer, 0, 0, 0) 
        end 
    end 
end 

Link to comment
Try this:
  
local timeBeforeSuicide = 5000 -- 5 seconds 
local suicideMoveCheckerTimer = 1000 -- 1 second 
function commitSuicide(thePlayer) 
    local px, py, pz = getElementPosition(thePlayer) --get the current position 
    local originPos = {x=px, y=py, z=pz} --store that pos in a table 
    setElementData(thePlayer, "originPos", originPos) --save it as an element data 
    local suicideTimer = setTimer(killPed, timeBeforeSuicide, 1, thePlayer, thePlayer) 
    setElementData(thePlayer, "suicideTimer", suicideTimer) 
    setTimer(suicidePosChecker, 1000, timeBeforeSuicide/1000, thePlayer) 
end 
addCommandHandler ( "kill", commitSuicide ) 
  
function suicidePosChecker(thePlayer) 
    local originPos = getElementData(thePlayer, "originPos") or {x=0, y=0, z=0} 
    local px, py, pz = getElementPosition(thePlayer) --get the new position 
    local distance = getDistanceBetweenPoints3D(px, py, pz, originPos.x, originPos.y, originPos.z) 
    if distance >= 2 then -- if the player moved at least 2 meters 
        local suicideTimer = getElementData(thePlayer, "suicideTimer") --get the timer 
        if suicideTimer then --if we got it, then  
            killTimer(suicideTimer) --kill it to prevent the suicide 
            outputChatBox("You moved and the suicide has been canceled !", thePlayer, 0, 0, 0) 
        end 
    end 
end 

WARNING : s\script.lua:21: Bad Argument @ 'killTimer' [Expected Lua-Timer at argument 1]

and also outputChatBox("#FFFF00[ADMIN BOT] You moved and the suicide has been canceled !", thePlayer, 0, 0, 0, true) repeat 9 times ... Thanks but can you help me to fix it again ... :?:

Link to comment
  • Moderators

Actually, this script is working, but I forgot we have a sort of a pointer to a timer so even if we kill that timer, the timer still has a value wich is not null or false.

I fixed that in this new version.

Btw it's now killing the checker timer too because it's not needed anymore when the player has moved:

local timeBeforeSuicide = 5000 -- 5 seconds 
local suicideMoveCheckerTimer = 1000 -- 1 second 
function commitSuicide(thePlayer) 
    local px, py, pz = getElementPosition(thePlayer) --get the current position 
    local originPos = {x=px, y=py, z=pz} --store that pos in a table 
    setElementData(thePlayer, "originPos", originPos) --save it as an element data 
    local suicideTimer = setTimer(killPed, timeBeforeSuicide, 1, thePlayer, thePlayer) 
    setElementData(thePlayer, "suicideTimer", suicideTimer) 
    local checkerTimer = setTimer(suicidePosChecker, suicideMoveCheckerTimer, timeBeforeSuicide/suicideMoveCheckerTimer, thePlayer) 
    setElementData(thePlayer, "suicideCheckerTimer", checkerTimer) 
end 
addCommandHandler ( "kill", commitSuicide ) 
  
function suicidePosChecker(thePlayer) 
    local originPos = getElementData(thePlayer, "originPos") or {x=0, y=0, z=0} 
    local px, py, pz = getElementPosition(thePlayer) --get the new position 
    local distance = getDistanceBetweenPoints3D(px, py, pz, originPos.x, originPos.y, originPos.z) 
    if distance >= 2 then -- if the player moved at least 2 meters 
        local suicideTimer = getElementData(thePlayer, "suicideTimer") --get the suicide timer 
        local checkerTimer = getElementData(thePlayer, "suicideCheckerTimer") --get the checker timer 
        if suicideTimer and checkerTimer then --if we got them, then 
            killTimer(suicideTimer) --kill it to prevent the suicide 
            killTimer(checkerTimer) --kill it to prevent checking again 
            removeElementData(thePlayer, "suicideTimer") 
            removeElementData(thePlayer, "suicideCheckerTimer") 
            outputChatBox("You moved and the suicide has been canceled !", thePlayer, 0, 0, 0) 
        end 
    end 
end 

Link to comment
Actually, this script is working, but I forgot we have a sort of a pointer to a timer so even if we kill that timer, the timer still has a value wich is not null or false.

I fixed that in this new version.

Btw it's now killing the checker timer too because it's not needed anymore when the player has moved:

local timeBeforeSuicide = 5000 -- 5 seconds 
local suicideMoveCheckerTimer = 1000 -- 1 second 
function commitSuicide(thePlayer) 
    local px, py, pz = getElementPosition(thePlayer) --get the current position 
    local originPos = {x=px, y=py, z=pz} --store that pos in a table 
    setElementData(thePlayer, "originPos", originPos) --save it as an element data 
    local suicideTimer = setTimer(killPed, timeBeforeSuicide, 1, thePlayer, thePlayer) 
    setElementData(thePlayer, "suicideTimer", suicideTimer) 
    local checkerTimer = setTimer(suicidePosChecker, suicideMoveCheckerTimer, timeBeforeSuicide/suicideMoveCheckerTimer, thePlayer) 
    setElementData(thePlayer, "suicideCheckerTimer", checkerTimer) 
end 
addCommandHandler ( "kill", commitSuicide ) 
  
function suicidePosChecker(thePlayer) 
    local originPos = getElementData(thePlayer, "originPos") or {x=0, y=0, z=0} 
    local px, py, pz = getElementPosition(thePlayer) --get the new position 
    local distance = getDistanceBetweenPoints3D(px, py, pz, originPos.x, originPos.y, originPos.z) 
    if distance >= 2 then -- if the player moved at least 2 meters 
        local suicideTimer = getElementData(thePlayer, "suicideTimer") --get the suicide timer 
        local checkerTimer = getElementData(thePlayer, "suicideCheckerTimer") --get the checker timer 
        if suicideTimer and checkerTimer then --if we got them, then 
            killTimer(suicideTimer) --kill it to prevent the suicide 
            killTimer(checkerTimer) --kill it to prevent checking again 
            removeElementData(thePlayer, "suicideTimer") 
            removeElementData(thePlayer, "suicideCheckerTimer") 
            outputChatBox("You moved and the suicide has been canceled !", thePlayer, 0, 0, 0) 
        end 
    end 
end 

Thanks bro :D you help me a lot :D8) you are good :D

Problem SOLVED :D

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...