Jump to content

[Help needed] Few issues


Absence2

Recommended Posts

Hey, I have some issues with this script me & my friend are developing, we're having few problems with the onPlayerWasted and the commandhandler - quitevent

  
  
local eventStarted = false 
local playerJoinedEvent = false 
local weaponEvent,ammo,eventEnded 
local pX,pY,pZ 
local adminPositionX,adminPositionY,adminPositionZ 
  
  
local weaponEquipped1,weaponEquipped2,weaponEquipped3,weaponEquipped4,weaponEquipped5,weaponEquipped6,weaponEquipped7,weaponEquipped8,weaponEquipped9,weaponEquipped10,weaponEquipped11,weaponEquipped12 
  
 function playerJoinsEvent(thePlayer, command,amount)    
  local skin = setElementModel(thePlayer, tonumber(skinID)) 
  if(eventStarted == true and playerJoinedEvent == false and command == "joinevent") then 
        pX,pY,pZ  = getElementPosition(thePlayer) 
  
  
    spawnPlayer(thePlayer,adminPositionX,adminPositionY,adminPositionZ,0,skinID) 
    playerJoinedEvent = true 
exports.global:giveWeapon (thePlayer,weaponEvent , tonumber(ammo)) 
    outputChatBox("You successfully joined the event",thePlayer) 
elseif(eventStarted == false and playerJoinedEvent == false and command == "joinevent")then 
    outputChatBox("#FF8000 |Event| : There is no event currently ongoing.",thePlayer, 42, 100, 100, true ) 
elseif(eventStarted == true and command == "joinevent" and playerJoinedEvent == true)then 
    outputChatBox("#FF8000 |Event| : You are already in the event",thePlayer,42, 100, 100, true ) 
end 
  
if(eventEnded == false and playerJoinedEvent == true and command == "endevent")then 
spawnPlayer(thePlayer,pX,pY,pZ,0,skin) 
eventEnded = true 
end 
  
  
if(command == "quitevent" and eventStarted == true and playerJoinedEvent == true)then 
spawnPlayer(thePlayer,pX,pY,pZ,0,skinID) 
playerJoinedEvent = false 
exports.global:takeAllWeapons(source) 
outputChatBox("#008000|Event| : You successfully quit the event.",thePlayer,42, 100, 100, true ) 
end 
end 
addCommandHandler("joinevent",playerJoinsEvent) 
addCommandHandler("quitevent",playerJoinsEvent) 
addCommandHandler("endevent",playerJoinsEvent) 
  
function adminStartEvent(thePlayer, command, weaponId, ammoCMD) 
  
if(eventStarted == false and command == "startevent" and weaponId ~= null)then 
--Declaring booleans and variables 
ammo = ammoCMD 
weaponEvent = weaponId 
eventEnded = false 
eventStarted = true 
local weaponName = getWeaponNameFromID (weaponEvent) 
adminPositionX,adminPositionY,adminPositionZ = getElementPosition(thePlayer) 
--*********************** 
outputChatBox("#FF8000 |Event| : Event started by Admin",getRootElement(),42, 100, 100, true ) 
outputChatBox("#FF8000 |Event| :  Weapon being used "..weaponName,thePlayer,42, 100, 100, true ) 
end 
if(eventStarted == false and command == "startevent" and weaponId == null)then  
outputChatBox("#FF0000 |Event|Syntax|: /startevent [weaponID][ammo]",thePlayer,42, 100, 100, true) 
end 
if(eventStarted == true and command == "endevent")then 
    eventStarted = false 
    eventEnded = true 
    playerJoinedEvent = false 
    outputChatBox("#FF8000 |Event| : Event ended by an Admin",thePlayer,42, 100, 100, true ) 
elseif(eventStarted == false and command == "endevent")then 
    outputChatBox("#FF0000 |Event| : There is no event in progress.",thePlayer,42, 100, 100, true ) 
     
end 
  
end 
addCommandHandler("startevent",adminStartEvent) 
addCommandHandler("endevent",adminStartEvent) 
  
  
function playerDied() 
    if(eventStarted == true and playerJoinedEvent == true)then 
    exports.global:takeAllWeapons(source) 
    spawnPlayer(source,pX,pY,pZ,0,skinID) 
end 
end 
addEventHandler("onPlayerWasted",getRootElement(),playerDied) 

So when you /quitevent, you basically return to your old position. We're do that aswell on function playerDied, if you die, you return there "without being killed", you just get thrown out of the event.

We also have some skin problems. It doesn't save your current skin while entering the event with /joinevent (skin sets to 0), and you come out with skin ID 0 if you die or /quitevent

^ Same goes for guns. takeAllWeapons takes the ones you had before the event too.

Any help here :?

Edited by Guest
Link to comment
Lua is Canse Sensitive.

OnPlayerWasted is nil.

It's onPlayerWasted

Oh, I must of missed that one. I corrected it and tried. when I die, I spawn back at the position before /joinevent, but the thing is, I die and then I just die and spawn at hospital. Also it didn't solve the other two things, skins & guns.

How to prevent that to happen and how to save skins & guns :shock: ?

(I die after being teleported back to my previous position)

Edited by Guest
Link to comment
local eventStarted = false 
local playersJoinedEvent = { } 
local weaponEvent, weaponAmmo, eventEnded 
local adminPositionX, adminPositionY, adminPositionZ 
local playersData = { } 
  
 function convertPlayerWeaponsToTable(player) 
    local weapons = { } 
    for slot = 0, 12 do 
        local weapon = getPedWeapon( player, slot ) 
        if ( weapon > 0 ) then 
            local ammo = getPedTotalAmmo( player, slot ) 
            if ( ammo > 0 ) then 
                weapons[weapon] = ammo 
            end 
        end 
    end 
    return weapons 
end 
  
function playerJoinsEvent ( thePlayer, command ) 
    if ( eventStarted == true and not playersJoinedEvent[thePlayer] and command == "joinevent" ) then 
        local pX, pY, pZ = getElementPosition ( thePlayer ) 
        local playerSkin = getElementModel ( thePlayer ) 
        playersData[thePlayer] = 
            { 
                position = { pX, pY, pZ }, 
                skin = playerSkin, 
                weapons = convertPlayerWeaponsToTable( thePlayer ) 
            } 
        if spawnPlayer( thePlayer, adminPositionX, adminPositionY, adminPositionZ, 0, tonumber( skinID ) ) then 
            playerJoinedEvent = true 
            giveWeapon ( thePlayer, weaponEvent, tonumber( weaponAmmo ) ) 
            outputChatBox( "You successfully joined the event", thePlayer ) 
            playersJoinedEvent[thePlayer] = true 
        end 
        
    elseif ( eventStarted == false and not playersJoinedEvent[thePlayer] and command == "joinevent" ) then 
        outputChatBox( "#FF8000 |Event| : There is no event currently ongoing.", thePlayer, 42, 100, 100, true ) 
    elseif ( eventStarted == true and playerJoinedEvent == true and command == "joinevent" ) then 
        outputChatBox( "#FF8000 |Event| : You are already in the event", thePlayer, 42, 100, 100, true ) 
    end 
        
    if ( eventEnded == false and not playersJoinedEvent[thePlayer] and command == "endevent" ) then 
        loadOriginalData ( thePlayer ) 
        eventEnded = true 
    end 
  
    if ( command == "quitevent" and eventStarted == true and playersJoinedEvent[thePlayer] )then 
        loadOriginalData ( thePlayer ) 
        outputChatBox( "#008000|Event| : You successfully quit the event.", thePlayer, 42, 100, 100, true ) 
    end 
end 
addCommandHandler("joinevent",playerJoinsEvent) 
addCommandHandler("quitevent",playerJoinsEvent) 
  
function loadOriginalData ( thePlayer ) 
    local savedData = playersData[thePlayer] 
    if ( savedData and type ( savedData ) == "table" ) then 
        local x, y, z = unpack ( savedData.position ) 
        playersJoinedEvent[thePlayer] = nil 
        local spawned = spawnPlayer( thePlayer, x, y, z, 0, savedData.skin) 
        if  (spawned ) then 
            takeAllWeapons ( thePlayer ) 
    
            for weapon, ammo in pairs ( savedData.weapons ) do 
                giveWeapon ( thePlayer, weapon, ammo ) 
            end 
        end 
    end 
end 
  
function adminStartEvent(thePlayer, command, weaponId, ammoCMD) 
    if ( eventStarted == false and command == "startevent" and weaponId ~= null ) then 
        playersData = { } 
        playersJoinedEvent = { } 
        --Declaring booleans and variables 
        weaponAmmo = ammoCMD 
        weaponEvent = weaponId 
        eventEnded = false 
        eventStarted = true 
        local weaponName = getWeaponNameFromID ( weaponEvent ) 
        adminPositionX, adminPositionY, adminPositionZ = getElementPosition ( thePlayer ) 
        --*********************** 
        outputChatBox( "#FF8000 |Event| : Event started by Admin", getRootElement( ), 42, 100, 100, true ) 
        outputChatBox( "#FF8000 |Event| :  Weapon being used ".. weaponName, thePlayer,42, 100, 100, true ) 
    end 
    if ( eventStarted == false and command == "startevent" and weaponId == null ) then 
        outputChatBox( "#FF0000 |Event|Syntax|: /startevent [weaponID][ammo]", thePlayer, 42, 100, 100, true ) 
    end 
    if ( eventStarted == true and command == "endevent" ) then 
        eventStarted = false 
        eventEnded = true 
        playerJoinedEvent = false 
        outputChatBox( "#FF8000 |Event| : Event ended by an Admin", thePlayer, 42, 100, 100, true ) 
    elseif ( eventStarted == false and command == "endevent" ) then 
        outputChatBox( "#FF0000 |Event| : There is no event in progress.", thePlayer, 42, 100, 100, true ) 
    end 
end 
addCommandHandler( "startevent", adminStartEvent ) 
addCommandHandler( "endevent", adminStartEvent ) 
  
addEventHandler( "onPlayerSpawn", getRootElement( ), 
    function  ( ) 
        if ( eventStarted == true and playersJoinedEvent[source] ) then 
            loadOriginalData ( source ) 
        end 
    end 
) 

Edit: Code updated.

Link to comment

Yes, I noticed, it might involve this,

the onPlayerWasted is still a problem. I really DIE if I die within the event which shouldn't happen :(, it should "kick" me from the event when I reach 0 hp and return me to the old position without killing me outside the event >.<

The skin & gun seems to be solved from what I can see

also I have a question, if someone /joinevent - their skins sets to 0, if they quit, it's normal. Can I change it somehow or use their default skin if they /joinevent?

EDIT: noticed a second error, it now doesn't spawn me to my previous (old) position when I /quitevent or /endevent, it probably includes while dieing, can't really check that one as I die for real. (It adds me to the current position I am at, lol).

^ works now, I saw that you edited your post :)

but it's just this, when dieing inside the event:

function playerDied() 
    if(eventStarted == true and playerJoinedEvent == true)then 
    exports.global:takeAllWeapons(source) 
    spawnPlayer(source,pX,pY,pZ,0,skinID) 
end 
end 
addEventHandler("onPlayerWasted",getRootElement(),playerDied) 

It kills you for real. =/ can't I cancel the event or something? When he hits 0 hp in the event he gets kicked from the event?

or your verison:

addEventHandler( "onPlayerWasted", getRootElement( ), 
    function  ( ) 
        if ( eventStarted == true and playerJoinedEvent == true ) then 
            loadOriginalData ( source ) 
        end 
    end 
) 
  

Link to comment
I have found the problem that caused the Stack overflow, copy my code again.

Thank you :) but I still need help with one of the big ones:

addEventHandler( "onPlayerWasted", getRootElement( ), 
    function  ( ) 
        if ( eventStarted == true and playerJoinedEvent == true ) then 
            loadOriginalData ( source ) 
        end 
    end 
) 
  

If he dies within /joinevent (Basically the event), he dies. He's only supposed to "Die within the event" and just TP back to his position after he gets killed inside the event. Any idea how to do this?

With this, he gets TPed back to his previous position THEN dies outside the event.

Link to comment
You can't cancel the death, you could always try to make a own "health" system which will not take real player health, but a fake one.

That sounds really hard, also I tried by turning off the respawn after death resource and it seems to be working fine while it's off.

mysql = exports.mysql 
local prisonmarker = createMarker ( 187.14199829102, 1868.3699951172, 17.746978759766, "cylinder", 250, 0, 0, 0, 0, 0 ) 
  
function playerDeath() 
    if getElementData(source, "dbid") then 
        local name = string.gsub(getPlayerName(source), "_", " ") 
        setPlayerNametagText(source, tostring(name)) 
        exports['anticheat-system']:changeProtectedElementDataEx(source, "nameTint", 0) 
  
        if getElementData(source, "adminjailed") then 
            spawnPlayer(source, 263.821807, 77.848365, 1001.0390625, 270, getElementModel(source), 0, getElementData(source, "playerid")+65400, getPlayerTeam(source)) 
            setCameraInterior(source, 6) 
            setCameraTarget(source) 
            fadeCamera(source, true) 
        else 
            outputChatBox("Respawn in 10 seconds.", source) 
            setTimer(respawnPlayer, 10000, 1, source) 
        end 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), playerDeath) 
  
function respawnPlayer(thePlayer) 
    if (isElement(thePlayer)) then 
        local cost = 0 
        local faction = false 
        if not exports.global:isPlayerSilverDonator(thePlayer) then 
            local team = getPlayerTeam(thePlayer) 
            if getTeamName(team) == "San Andreas Network" then 
                _, cost = exports.global:takeMoney(team, math.random(150, 300), true) 
                faction = getTeamName(team) 
            else 
                _, cost = exports.global:takeMoney(thePlayer, math.random(150, 300), true) 
            end 
        end 
         
        local tax = exports.global:getTaxAmount() 
         
        exports.global:giveMoney( getTeamFromName("Las Venturas Emergency Services"), math.ceil((1-tax)*cost) ) 
        exports.global:giveMoney( getTeamFromName("Government of Los Santos"), math.ceil(tax*cost) ) 
             
        mysql:query_free("UPDATE characters SET deaths = deaths + 1 WHERE charactername='" .. mysql:escape_string(getPlayerName(thePlayer)) .. "'") 
  
        setCameraInterior(thePlayer, 0) 
             
        local text = "You have recieved treatment from the Los Santos Medical Center." 
        if cost > 0 then 
            text = text .. " Cost: " .. cost .. "$" 
        end 
        if faction then 
            text = text .. ", paid by " .. faction .. "." 
        end 
        outputChatBox(text, thePlayer, 255, 255, 0) 
         
        -- take all drugs 
        local count = 0 
        for i = 30, 43 do 
            while exports.global:hasItem(thePlayer, i) do 
                exports.global:takeItem(thePlayer, i) 
                count = count + 1 
            end 
        end 
        if count > 0 then 
            outputChatBox("The illegal substances you had have been handed over to investigators.", thePlayer, 255, 194, 14) 
        end 
             
        local theSkin = getPedSkin(thePlayer) 
             
        local theTeam = getPlayerTeam(thePlayer) 
         
        local fat = getPedStat(thePlayer, 21) 
        local muscle = getPedStat(thePlayer, 23) 
             
        setPedStat(thePlayer, 21, fat) 
        setPedStat(thePlayer, 23, muscle) 
         
        spawnPlayer(thePlayer,1185.296875, -1323.7158203125, 13.572407722473, 0, theSkin, 0, 0, theTeam) 
             
        fadeCamera(thePlayer, true, 6) 
        triggerClientEvent(thePlayer, "fadeCameraOnSpawn", thePlayer) 
    end 
end 
  
function deathRemoveWeapons(weapons, removedWeapons) 
    setTimer(giveGunsBack, 10005, 1, source, weapons, removedWeapons) 
end 
addEvent("onDeathRemovePlayerWeapons", true) 
addEventHandler("onDeathRemovePlayerWeapons", getRootElement(), deathRemoveWeapons) 
  
function giveGunsBack(thePlayer, weapons, removedWeapons, removedWeapons2) 
    if (removedWeapons~=nil) then 
        if tonumber(getElementData(thePlayer, "license.gun")) == 0 and getElementData(getPlayerTeam(thePlayer),"type") ~= 2 then 
        outputChatBox("The employees have taken away weapons which you did not have a license for. (" .. removedWeapons .. ").", thePlayer, 255, 194, 14) 
        else 
            outputChatBox("The employees have taken away weapons which you are not allowed to carry. (" .. removedWeapons .. ").", thePlayer, 255, 194, 14) 
        end 
    end 
    if removedWeapons2 ~= nil then 
        outputChatBox("The employees have taken away your " .. removedWeapons2 .. " for safety purposes.", thePlayer, 255, 194, 14) 
    end 
    -- 28 
    for key, value in ipairs(weapons) do 
        local weapon = tonumber(weapons[key][1]) 
        local ammo = tonumber(weapons[key][2]) 
        local removed = tonumber(weapons[key][3]) 
         
        if (removed==0) then 
            exports.global:giveWeapon(thePlayer, weapon, math.floor( ammo / 2 ), false) 
        else 
            exports.global:takeWeapon(thePlayer, weapon) 
            exports.logs:logMessage("[Death] " .. getElementData(thePlayer, "gameaccountusername") .. "/" .. getPlayerName(thePlayer) .. " lost a weapon (" .. getWeaponNameFromID (weapon) .. "/".. tostring(ammo) .." ammo)", 28) 
        end 
    end 
end 

Is there anything I can do about that then >.<? Or is "fake health" my only option?

Link to comment

You can use a variable with a boolean value to see if player is in the event, then your respawn system will only kill and spawn player if the player isn't in a event. But you will need to put all in the same script.

Link to comment
You can use a variable with a boolean value to see if player is in the event, then your respawn system will only kill and spawn player if the player isn't in a event. But you will need to put all in the same script.

Last part there won't really be a problem. But isn't this the same thing as "canceling death"? o_o

and do you mean something like this:

function playerDeath() 
    if getElementData(source, "dbid") then 
        local name = string.gsub(getPlayerName(source), "_", " ") 
        setPlayerNametagText(source, tostring(name)) 
        exports['anticheat-system']:changeProtectedElementDataEx(source, "nameTint", 0) 
  
        if getElementData(source, "adminjailed") then 
            spawnPlayer(source, 263.821807, 77.848365, 1001.0390625, 270, getElementModel(source), 0, getElementData(source, "playerid")+65400, getPlayerTeam(source)) 
            setCameraInterior(source, 6) 
            setCameraTarget(source) 
            fadeCamera(source, true) 
        else 
            outputChatBox("Respawn in 10 seconds.", source) 
            setTimer(respawnPlayer, 10000, 1, source) 
             
        else 
        playersJoinedEvent = true 
        spawnPlayer = false      
        end 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), playerDeath)  

EDIT: that didn't work at all ^ :oops:, it even made things worse lol

Link to comment

Because you have syntax error.

  
if then 
  
else 
  
else 
  
end 
  

lol?

viewtopic.php?f=148&t=40809

function playerDeath() 
    if getElementData( source, "dbid" ) then 
        local name = string.gsub( getPlayerName( source ), "_", " " ) 
        setPlayerNametagText( source, tostring( name ) ) 
        exports['anticheat-system']:changeProtectedElementDataEx(source, "nameTint", 0) 
  
        if getElementData(source, "adminjailed") then 
            spawnPlayer(source, 263.821807, 77.848365, 1001.0390625, 270, getElementModel(source), 0, getElementData(source, "playerid")+65400, getPlayerTeam(source)) 
            setCameraInterior(source, 6) 
            setCameraTarget(source) 
            fadeCamera(source, true) 
        else 
            outputChatBox("Respawn in 10 seconds.", source) 
            setTimer(respawnPlayer, 10000, 1, source) 
             
        end   
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), playerDeath)  

Variable respawnPlayer is defined?

Link to comment

I know I had syntax error, I fixed it the second after I posted. I just forgot to update it. Hence the EDIT: :D

Anyways, this is everything I got related to this:

mysql = exports.mysql 
local prisonmarker = createMarker ( 187.14199829102, 1868.3699951172, 17.746978759766, "cylinder", 250, 0, 0, 0, 0, 0 ) 
  
function playerDeath() 
    if getElementData(source, "dbid") then 
        local name = string.gsub(getPlayerName(source), "_", " ") 
        local eventStarted = false 
local playersJoinedEvent = { } 
local weaponEvent, weaponAmmo, eventEnded 
local adminPositionX, adminPositionY, adminPositionZ 
local playersData = { } 
        setPlayerNametagText(source, tostring(name)) 
        exports['anticheat-system']:changeProtectedElementDataEx(source, "nameTint", 0) 
         
        if getElementData(source, "adminjailed") then 
            spawnPlayer(source, 263.821807, 77.848365, 1001.0390625, 270, getElementModel(source), 0, getElementData(source, "playerid")+65400, getPlayerTeam(source)) 
            setCameraInterior(source, 6) 
            setCameraTarget(source) 
            fadeCamera(source, true) 
        else 
            outputChatBox("Respawn in 10 seconds.", source) 
            setTimer(respawnPlayer, 10000, 1, source) 
     
        playersJoinedEvent = true 
        spawnPlayer = false      
        end 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), playerDeath) 
  
function respawnPlayer(thePlayer) 
    if (isElement(thePlayer)) then 
        local cost = 0 
        local faction = false 
        if not exports.global:isPlayerSilverDonator(thePlayer) then 
            local team = getPlayerTeam(thePlayer) 
            if getTeamName(team) == "San Andreas Network" then 
                _, cost = exports.global:takeMoney(team, math.random(150, 300), true) 
                faction = getTeamName(team) 
            else 
                _, cost = exports.global:takeMoney(thePlayer, math.random(150, 300), true) 
            end 
        end 
         
        local tax = exports.global:getTaxAmount() 
         
        exports.global:giveMoney( getTeamFromName("Las Venturas Emergency Services"), math.ceil((1-tax)*cost) ) 
        exports.global:giveMoney( getTeamFromName("Government of Los Santos"), math.ceil(tax*cost) ) 
             
        mysql:query_free("UPDATE characters SET deaths = deaths + 1 WHERE charactername='" .. mysql:escape_string(getPlayerName(thePlayer)) .. "'") 
  
        setCameraInterior(thePlayer, 0) 
             
        local text = "You have recieved treatment from the Los Santos Medical Center." 
        if cost > 0 then 
            text = text .. " Cost: " .. cost .. "$" 
        end 
        if faction then 
            text = text .. ", paid by " .. faction .. "." 
        end 
        outputChatBox(text, thePlayer, 255, 255, 0) 
         
        -- take all drugs 
        local count = 0 
        for i = 30, 43 do 
            while exports.global:hasItem(thePlayer, i) do 
                exports.global:takeItem(thePlayer, i) 
                count = count + 1 
            end 
        end 
        if count > 0 then 
            outputChatBox("The illegal substances you had have been handed over to investigators.", thePlayer, 255, 194, 14) 
        end 
             
        local theSkin = getPedSkin(thePlayer) 
             
        local theTeam = getPlayerTeam(thePlayer) 
         
        local fat = getPedStat(thePlayer, 21) 
        local muscle = getPedStat(thePlayer, 23) 
             
        setPedStat(thePlayer, 21, fat) 
        setPedStat(thePlayer, 23, muscle) 
         
        spawnPlayer(thePlayer,1185.296875, -1323.7158203125, 13.572407722473, 0, theSkin, 0, 0, theTeam) 
             
        fadeCamera(thePlayer, true, 6) 
        triggerClientEvent(thePlayer, "fadeCameraOnSpawn", thePlayer) 
    end 
end 
  
function deathRemoveWeapons(weapons, removedWeapons) 
    setTimer(giveGunsBack, 10005, 1, source, weapons, removedWeapons) 
end 
addEvent("onDeathRemovePlayerWeapons", true) 
addEventHandler("onDeathRemovePlayerWeapons", getRootElement(), deathRemoveWeapons) 
  
function giveGunsBack(thePlayer, weapons, removedWeapons, removedWeapons2) 
    if (removedWeapons~=nil) then 
        if tonumber(getElementData(thePlayer, "license.gun")) == 0 and getElementData(getPlayerTeam(thePlayer),"type") ~= 2 then 
        outputChatBox("The employees have taken away weapons which you did not have a license for. (" .. removedWeapons .. ").", thePlayer, 255, 194, 14) 
        else 
            outputChatBox("The employees have taken away weapons which you are not allowed to carry. (" .. removedWeapons .. ").", thePlayer, 255, 194, 14) 
        end 
    end 
    if removedWeapons2 ~= nil then 
        outputChatBox("The employees have taken away your " .. removedWeapons2 .. " for safety purposes.", thePlayer, 255, 194, 14) 
    end 
    -- 28 
    for key, value in ipairs(weapons) do 
        local weapon = tonumber(weapons[key][1]) 
        local ammo = tonumber(weapons[key][2]) 
        local removed = tonumber(weapons[key][3]) 
         
        if (removed==0) then 
            exports.global:giveWeapon(thePlayer, weapon, math.floor( ammo / 2 ), false) 
        else 
            exports.global:takeWeapon(thePlayer, weapon) 
            exports.logs:logMessage("[Death] " .. getElementData(thePlayer, "gameaccountusername") .. "/" .. getPlayerName(thePlayer) .. " lost a weapon (" .. getWeaponNameFromID (weapon) .. "/".. tostring(ammo) .." ammo)", 28) 
        end 
    end 
end 
  
  
local eventStarted = false 
local playersJoinedEvent = { } 
local weaponEvent, weaponAmmo, eventEnded 
local adminPositionX, adminPositionY, adminPositionZ 
local playersData = { } 
  
 function convertPlayerWeaponsToTable(player) 
    local weapons = { } 
    for slot = 0, 12 do 
        local weapon = getPedWeapon( player, slot ) 
        if ( weapon > 0 ) then 
            local ammo = getPedTotalAmmo( player, slot ) 
            if ( ammo > 0 ) then 
                weapons[weapon] = ammo 
            end 
        end 
    end 
    return weapons 
end 
  
function playerJoinsEvent ( thePlayer, command ) 
    if ( eventStarted == true and not playersJoinedEvent[thePlayer] and command == "joinevent" ) then 
        local pX, pY, pZ = getElementPosition ( thePlayer ) 
        local randomobjectnumber = math.random(1, 300) 
        local playerSkin = getElementModel ( thePlayer ) 
        playersData[thePlayer] = 
            { 
                position = { pX, pY, pZ }, 
                skin = playerSkin, 
                weapons = convertPlayerWeaponsToTable( thePlayer ) 
            } 
        if spawnPlayer( thePlayer, adminPositionX, adminPositionY, adminPositionZ, 0, tonumber( skinID ) ) then 
            playerJoinedEvent = true 
            setElementModel ( thePlayer, randomobjectnumber ) 
            exports.global:giveWeapon ( thePlayer, weaponEvent, tonumber( weaponAmmo ) ) 
            outputChatBox( "#FFFFFFEVENT: You successfully joined the event", thePlayer, 255, 255, 255, true ) 
            playersJoinedEvent[thePlayer] = true 
        end 
        
    elseif ( eventStarted == false and not playersJoinedEvent[thePlayer] and command == "joinevent" ) then 
        outputChatBox( "#FFFFFFEVENT: There is no event currently ongoing.", thePlayer, 255, 255, 255, true ) 
    elseif ( eventStarted == true and playerJoinedEvent == true and command == "joinevent" ) then 
        outputChatBox( "#FFFFFFEVENT: You are already in the event", thePlayer, 255, 255, 255, true ) 
    end 
        
    if ( eventEnded == false and not playersJoinedEvent[thePlayer] and command == "endevent" ) then 
        loadOriginalData ( thePlayer ) 
        eventEnded = true 
    end 
  
    if ( command == "quitevent" and eventStarted == true and playersJoinedEvent[thePlayer] )then 
        loadOriginalData ( thePlayer ) 
        outputChatBox( "#FFFFFFEVENT: You successfully quit the event.", thePlayer, 255, 255, 255, true ) 
    end 
end 
addCommandHandler("joinevent",playerJoinsEvent) 
addCommandHandler("quitevent",playerJoinsEvent) 
  
function loadOriginalData ( thePlayer ) 
    local savedData = playersData[thePlayer] 
    if ( savedData and type ( savedData ) == "table" ) then 
        local x, y, z = unpack ( savedData.position ) 
        playersJoinedEvent[thePlayer] = nil 
        local spawned = spawnPlayer( thePlayer, x, y, z, 0, savedData.skin) 
        if  (spawned ) then 
            takeAllWeapons ( thePlayer ) 
    
            for weapon, ammo in pairs ( savedData.weapons ) do 
                exports.global:giveWeapon ( thePlayer, weapon, ammo ) 
            end 
        end 
    end 
end 
  
function adminStartEvent(thePlayer, command, weaponId, ammoCMD) 
    if ( eventStarted == false and command == "startevent" and weaponId ~= null ) then 
        playersData = { } 
        playersJoinedEvent = { } 
        --Declaring booleans and variables 
        weaponAmmo = ammoCMD 
        weaponEvent = weaponId 
        eventEnded = false 
        eventStarted = true 
        local weaponName = getWeaponNameFromID ( weaponEvent ) 
        adminPositionX, adminPositionY, adminPositionZ = getElementPosition ( thePlayer ) 
        --*********************** 
        outputChatBox( "#FFFFFFEVENT: Event started by Admin", getRootElement( ), 255, 255, 255, true ) 
        outputChatBox( "#FFFFFFEVENT:  Weapon being used ".. weaponName, thePlayer,255, 255, 255, true ) 
    end 
    if ( eventStarted == false and command == "startevent" and weaponId == null ) then 
        outputChatBox( "SYNTAX: /startevent [weaponID] [ammo]", thePlayer, 255, 194, 14, true ) 
    end 
    if ( eventStarted == true and command == "endevent" ) then 
        eventStarted = false 
        eventEnded = true 
        playerJoinedEvent = false 
        outputChatBox( "#FFFFFFEVENT: Event ended by an Admin", thePlayer, 255, 255, 255, true ) 
    elseif ( eventStarted == false and command == "endevent" ) then 
        outputChatBox( "#FFFFFFEVENT: There is no event in progress.", thePlayer, 255, 255, 255, true ) 
    end 
end 
addCommandHandler( "startevent", adminStartEvent ) 
addCommandHandler( "endevent", adminStartEvent ) 
  
addEventHandler( "onPlayerSpawn", getRootElement( ), 
    function  ( ) 
        if ( eventStarted == true and playersJoinedEvent[source] ) then 
            loadOriginalData ( source ) 
        end 
    end 
) 
  
addEventHandler( "onPlayerWasted", getRootElement( ), 
    function  ( ) 
        if ( eventStarted == true and playerJoinedEvent == true ) then 
            loadOriginalData ( source ) 
        end 
    end 
) 
  

Link to comment
You can use a variable with a boolean value to see if player is in the event, then your respawn system will only kill and spawn player if the player isn't in a event. But you will need to put all in the same script.

I'm trying to do this somehow. But what I did just messed up the spawn after dieing o.O

Link to comment
I not understand what you want :S

if he's in the event and I disable the first script, he doesn't die in the event. if enabled, he dies. as Draken said, I'm trying to "detect" if he's in event wih /joinevent and then to ignore players in event or something when dieing, no idea how to explain :P go to page 1 :lol:

(I want the player to do the same thing when the /quitevent and when he dies, but the first script messes that up, so I'm lost, that's what I need help with

Link to comment
mysql = exports.mysql 
local prisonmarker = createMarker ( 187.14199829102, 1868.3699951172, 17.746978759766, "cylinder", 250, 0, 0, 0, 0, 0 ) 
  
function playerDeath() 
    if getElementData(source, "dbid") then 
        local name = string.gsub(getPlayerName(source), "_", " ") 
        local eventStarted = false 
local playersJoinedEvent = { } 
local weaponEvent, weaponAmmo, eventEnded 
local adminPositionX, adminPositionY, adminPositionZ 
local playersData = { } 
        setPlayerNametagText(source, tostring(name)) 
        exports['anticheat-system']:changeProtectedElementDataEx(source, "nameTint", 0) 
         
        if getElementData(source, "adminjailed") then 
            spawnPlayer(source, 263.821807, 77.848365, 1001.0390625, 270, getElementModel(source), 0, getElementData(source, "playerid")+65400, getPlayerTeam(source)) 
            setCameraInterior(source, 6) 
            setCameraTarget(source) 
            fadeCamera(source, true) 
        else 
            outputChatBox("Respawn in 10 seconds.", source) 
            setTimer(respawnPlayer, 10000, 1, source) 
     
        playersJoinedEvent = true 
        spawnPlayer = false      
        end 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), playerDeath) 
  
function respawnPlayer(thePlayer) 
    if (isElement(thePlayer)) then 
        local cost = 0 
        local faction = false 
        if not exports.global:isPlayerSilverDonator(thePlayer) then 
            local team = getPlayerTeam(thePlayer) 
            if getTeamName(team) == "San Andreas Network" then 
                _, cost = exports.global:takeMoney(team, math.random(150, 300), true) 
                faction = getTeamName(team) 
            else 
                _, cost = exports.global:takeMoney(thePlayer, math.random(150, 300), true) 
            end 
        end 
         
        local tax = exports.global:getTaxAmount() 
         
        exports.global:giveMoney( getTeamFromName("Las Venturas Emergency Services"), math.ceil((1-tax)*cost) ) 
        exports.global:giveMoney( getTeamFromName("Government of Los Santos"), math.ceil(tax*cost) ) 
             
        mysql:query_free("UPDATE characters SET deaths = deaths + 1 WHERE charactername='" .. mysql:escape_string(getPlayerName(thePlayer)) .. "'") 
  
        setCameraInterior(thePlayer, 0) 
             
        local text = "You have recieved treatment from the Los Santos Medical Center." 
        if cost > 0 then 
            text = text .. " Cost: " .. cost .. "$" 
        end 
        if faction then 
            text = text .. ", paid by " .. faction .. "." 
        end 
        outputChatBox(text, thePlayer, 255, 255, 0) 
         
        -- take all drugs 
        local count = 0 
        for i = 30, 43 do 
            while exports.global:hasItem(thePlayer, i) do 
                exports.global:takeItem(thePlayer, i) 
                count = count + 1 
            end 
        end 
        if count > 0 then 
            outputChatBox("The illegal substances you had have been handed over to investigators.", thePlayer, 255, 194, 14) 
        end 
             
        local theSkin = getPedSkin(thePlayer) 
             
        local theTeam = getPlayerTeam(thePlayer) 
         
        local fat = getPedStat(thePlayer, 21) 
        local muscle = getPedStat(thePlayer, 23) 
             
        setPedStat(thePlayer, 21, fat) 
        setPedStat(thePlayer, 23, muscle) 
         
        spawnPlayer(thePlayer,1185.296875, -1323.7158203125, 13.572407722473, 0, theSkin, 0, 0, theTeam) 
             
        fadeCamera(thePlayer, true, 6) 
        triggerClientEvent(thePlayer, "fadeCameraOnSpawn", thePlayer) 
    end 
end 
  
function deathRemoveWeapons(weapons, removedWeapons) 
    setTimer(giveGunsBack, 10005, 1, source, weapons, removedWeapons) 
end 
addEvent("onDeathRemovePlayerWeapons", true) 
addEventHandler("onDeathRemovePlayerWeapons", getRootElement(), deathRemoveWeapons) 
  
function giveGunsBack(thePlayer, weapons, removedWeapons, removedWeapons2) 
    if (removedWeapons~=nil) then 
        if tonumber(getElementData(thePlayer, "license.gun")) == 0 and getElementData(getPlayerTeam(thePlayer),"type") ~= 2 then 
        outputChatBox("The employees have taken away weapons which you did not have a license for. (" .. removedWeapons .. ").", thePlayer, 255, 194, 14) 
        else 
            outputChatBox("The employees have taken away weapons which you are not allowed to carry. (" .. removedWeapons .. ").", thePlayer, 255, 194, 14) 
        end 
    end 
    if removedWeapons2 ~= nil then 
        outputChatBox("The employees have taken away your " .. removedWeapons2 .. " for safety purposes.", thePlayer, 255, 194, 14) 
    end 
    -- 28 
    for key, value in ipairs(weapons) do 
        local weapon = tonumber(weapons[key][1]) 
        local ammo = tonumber(weapons[key][2]) 
        local removed = tonumber(weapons[key][3]) 
         
        if (removed==0) then 
            exports.global:giveWeapon(thePlayer, weapon, math.floor( ammo / 2 ), false) 
        else 
            exports.global:takeWeapon(thePlayer, weapon) 
            exports.logs:logMessage("[Death] " .. getElementData(thePlayer, "gameaccountusername") .. "/" .. getPlayerName(thePlayer) .. " lost a weapon (" .. getWeaponNameFromID (weapon) .. "/".. tostring(ammo) .." ammo)", 28) 
        end 
    end 
end 
  
  
local eventStarted = false 
local playersJoinedEvent = { } 
local weaponEvent, weaponAmmo, eventEnded 
local adminPositionX, adminPositionY, adminPositionZ 
local playersData = { } 
  
 function convertPlayerWeaponsToTable(player) 
    local weapons = { } 
    for slot = 0, 12 do 
        local weapon = getPedWeapon( player, slot ) 
        if ( weapon > 0 ) then 
            local ammo = getPedTotalAmmo( player, slot ) 
            if ( ammo > 0 ) then 
                weapons[weapon] = ammo 
            end 
        end 
    end 
    return weapons 
end 
  
function playerJoinsEvent ( thePlayer, command ) 
    if ( eventStarted == true and not playersJoinedEvent[thePlayer] and command == "joinevent" ) then 
        local pX, pY, pZ = getElementPosition ( thePlayer ) 
        local randomobjectnumber = math.random(1, 300) 
        local playerSkin = getElementModel ( thePlayer ) 
        playersData[thePlayer] = 
            { 
                position = { pX, pY, pZ }, 
                skin = playerSkin, 
                weapons = convertPlayerWeaponsToTable( thePlayer ) 
            } 
        if spawnPlayer( thePlayer, adminPositionX, adminPositionY, adminPositionZ, 0, tonumber( skinID ) ) then 
            playerJoinedEvent = true 
            setElementModel ( thePlayer, randomobjectnumber ) 
            exports.global:giveWeapon ( thePlayer, weaponEvent, tonumber( weaponAmmo ) ) 
            outputChatBox( "#FFFFFFEVENT: You successfully joined the event", thePlayer, 255, 255, 255, true ) 
            playersJoinedEvent[thePlayer] = true 
        end 
        
    elseif ( eventStarted == false and not playersJoinedEvent[thePlayer] and command == "joinevent" ) then 
        outputChatBox( "#FFFFFFEVENT: There is no event currently ongoing.", thePlayer, 255, 255, 255, true ) 
    elseif ( eventStarted == true and playerJoinedEvent == true and command == "joinevent" ) then 
        outputChatBox( "#FFFFFFEVENT: You are already in the event", thePlayer, 255, 255, 255, true ) 
    end 
        
    if ( eventEnded == false and not playersJoinedEvent[thePlayer] and command == "endevent" ) then 
        loadOriginalData ( thePlayer ) 
        eventEnded = true 
    end 
  
    if ( command == "quitevent" and eventStarted == true and playersJoinedEvent[thePlayer] )then 
        --loadOriginalData ( thePlayer ) 
        killPed( thePlayer ) 
        outputChatBox( "#FFFFFFEVENT: You successfully quit the event.", thePlayer, 255, 255, 255, true ) 
    end 
end 
addCommandHandler("joinevent",playerJoinsEvent) 
addCommandHandler("quitevent",playerJoinsEvent) 
  
function loadOriginalData ( thePlayer ) 
    local savedData = playersData[thePlayer] 
    if ( savedData and type ( savedData ) == "table" ) then 
        local x, y, z = unpack ( savedData.position ) 
        playersJoinedEvent[thePlayer] = nil 
        local spawned = spawnPlayer( thePlayer, x, y, z, 0, savedData.skin) 
        if  (spawned ) then 
            takeAllWeapons ( thePlayer ) 
    
            for weapon, ammo in pairs ( savedData.weapons ) do 
                exports.global:giveWeapon ( thePlayer, weapon, ammo ) 
            end 
        end 
    end 
end 
  
function adminStartEvent(thePlayer, command, weaponId, ammoCMD) 
    if ( eventStarted == false and command == "startevent" and weaponId ~= null ) then 
        playersData = { } 
        playersJoinedEvent = { } 
        --Declaring booleans and variables 
        weaponAmmo = ammoCMD 
        weaponEvent = weaponId 
        eventEnded = false 
        eventStarted = true 
        local weaponName = getWeaponNameFromID ( weaponEvent ) 
        adminPositionX, adminPositionY, adminPositionZ = getElementPosition ( thePlayer ) 
        --*********************** 
        outputChatBox( "#FFFFFFEVENT: Event started by Admin", getRootElement( ), 255, 255, 255, true ) 
        outputChatBox( "#FFFFFFEVENT:  Weapon being used ".. weaponName, thePlayer,255, 255, 255, true ) 
    end 
    if ( eventStarted == false and command == "startevent" and weaponId == null ) then 
        outputChatBox( "SYNTAX: /startevent [weaponID] [ammo]", thePlayer, 255, 194, 14, true ) 
    end 
    if ( eventStarted == true and command == "endevent" ) then 
        eventStarted = false 
        eventEnded = true 
        playerJoinedEvent = false 
        outputChatBox( "#FFFFFFEVENT: Event ended by an Admin", thePlayer, 255, 255, 255, true ) 
    elseif ( eventStarted == false and command == "endevent" ) then 
        outputChatBox( "#FFFFFFEVENT: There is no event in progress.", thePlayer, 255, 255, 255, true ) 
    end 
end 
addCommandHandler( "startevent", adminStartEvent ) 
addCommandHandler( "endevent", adminStartEvent ) 
  
addEventHandler( "onPlayerSpawn", getRootElement( ), 
    function  ( ) 
        if ( eventStarted == true and playersJoinedEvent[source] ) then 
            loadOriginalData ( source ) 
        end 
    end 
) 
  
addEventHandler( "onPlayerWasted", getRootElement( ), 
    function  ( ) 
        if ( eventStarted == true and playerJoinedEvent == true ) then 
            loadOriginalData ( source ) 
        end 
    end 
) 
  

You mean it?

See line 177

If you type cmd /quitevent you killed and respawned.

Link to comment
mysql = exports.mysql 
local prisonmarker = createMarker ( 187.14199829102, 1868.3699951172, 17.746978759766, "cylinder", 250, 0, 0, 0, 0, 0 ) 
  
function playerDeath() 
    if getElementData(source, "dbid") then 
        local name = string.gsub(getPlayerName(source), "_", " ") 
        local eventStarted = false 
local playersJoinedEvent = { } 
local weaponEvent, weaponAmmo, eventEnded 
local adminPositionX, adminPositionY, adminPositionZ 
local playersData = { } 
        setPlayerNametagText(source, tostring(name)) 
        exports['anticheat-system']:changeProtectedElementDataEx(source, "nameTint", 0) 
         
        if getElementData(source, "adminjailed") then 
            spawnPlayer(source, 263.821807, 77.848365, 1001.0390625, 270, getElementModel(source), 0, getElementData(source, "playerid")+65400, getPlayerTeam(source)) 
            setCameraInterior(source, 6) 
            setCameraTarget(source) 
            fadeCamera(source, true) 
        else 
            outputChatBox("Respawn in 10 seconds.", source) 
            setTimer(respawnPlayer, 10000, 1, source) 
     
        playersJoinedEvent = true 
        spawnPlayer = false      
        end 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), playerDeath) 
  
function respawnPlayer(thePlayer) 
    if (isElement(thePlayer)) then 
        local cost = 0 
        local faction = false 
        if not exports.global:isPlayerSilverDonator(thePlayer) then 
            local team = getPlayerTeam(thePlayer) 
            if getTeamName(team) == "San Andreas Network" then 
                _, cost = exports.global:takeMoney(team, math.random(150, 300), true) 
                faction = getTeamName(team) 
            else 
                _, cost = exports.global:takeMoney(thePlayer, math.random(150, 300), true) 
            end 
        end 
         
        local tax = exports.global:getTaxAmount() 
         
        exports.global:giveMoney( getTeamFromName("Las Venturas Emergency Services"), math.ceil((1-tax)*cost) ) 
        exports.global:giveMoney( getTeamFromName("Government of Los Santos"), math.ceil(tax*cost) ) 
             
        mysql:query_free("UPDATE characters SET deaths = deaths + 1 WHERE charactername='" .. mysql:escape_string(getPlayerName(thePlayer)) .. "'") 
  
        setCameraInterior(thePlayer, 0) 
             
        local text = "You have recieved treatment from the Los Santos Medical Center." 
        if cost > 0 then 
            text = text .. " Cost: " .. cost .. "$" 
        end 
        if faction then 
            text = text .. ", paid by " .. faction .. "." 
        end 
        outputChatBox(text, thePlayer, 255, 255, 0) 
         
        -- take all drugs 
        local count = 0 
        for i = 30, 43 do 
            while exports.global:hasItem(thePlayer, i) do 
                exports.global:takeItem(thePlayer, i) 
                count = count + 1 
            end 
        end 
        if count > 0 then 
            outputChatBox("The illegal substances you had have been handed over to investigators.", thePlayer, 255, 194, 14) 
        end 
             
        local theSkin = getPedSkin(thePlayer) 
             
        local theTeam = getPlayerTeam(thePlayer) 
         
        local fat = getPedStat(thePlayer, 21) 
        local muscle = getPedStat(thePlayer, 23) 
             
        setPedStat(thePlayer, 21, fat) 
        setPedStat(thePlayer, 23, muscle) 
         
        spawnPlayer(thePlayer,1185.296875, -1323.7158203125, 13.572407722473, 0, theSkin, 0, 0, theTeam) 
             
        fadeCamera(thePlayer, true, 6) 
        triggerClientEvent(thePlayer, "fadeCameraOnSpawn", thePlayer) 
    end 
end 
  
function deathRemoveWeapons(weapons, removedWeapons) 
    setTimer(giveGunsBack, 10005, 1, source, weapons, removedWeapons) 
end 
addEvent("onDeathRemovePlayerWeapons", true) 
addEventHandler("onDeathRemovePlayerWeapons", getRootElement(), deathRemoveWeapons) 
  
function giveGunsBack(thePlayer, weapons, removedWeapons, removedWeapons2) 
    if (removedWeapons~=nil) then 
        if tonumber(getElementData(thePlayer, "license.gun")) == 0 and getElementData(getPlayerTeam(thePlayer),"type") ~= 2 then 
        outputChatBox("The employees have taken away weapons which you did not have a license for. (" .. removedWeapons .. ").", thePlayer, 255, 194, 14) 
        else 
            outputChatBox("The employees have taken away weapons which you are not allowed to carry. (" .. removedWeapons .. ").", thePlayer, 255, 194, 14) 
        end 
    end 
    if removedWeapons2 ~= nil then 
        outputChatBox("The employees have taken away your " .. removedWeapons2 .. " for safety purposes.", thePlayer, 255, 194, 14) 
    end 
    -- 28 
    for key, value in ipairs(weapons) do 
        local weapon = tonumber(weapons[key][1]) 
        local ammo = tonumber(weapons[key][2]) 
        local removed = tonumber(weapons[key][3]) 
         
        if (removed==0) then 
            exports.global:giveWeapon(thePlayer, weapon, math.floor( ammo / 2 ), false) 
        else 
            exports.global:takeWeapon(thePlayer, weapon) 
            exports.logs:logMessage("[Death] " .. getElementData(thePlayer, "gameaccountusername") .. "/" .. getPlayerName(thePlayer) .. " lost a weapon (" .. getWeaponNameFromID (weapon) .. "/".. tostring(ammo) .." ammo)", 28) 
        end 
    end 
end 
  
  
local eventStarted = false 
local playersJoinedEvent = { } 
local weaponEvent, weaponAmmo, eventEnded 
local adminPositionX, adminPositionY, adminPositionZ 
local playersData = { } 
  
 function convertPlayerWeaponsToTable(player) 
    local weapons = { } 
    for slot = 0, 12 do 
        local weapon = getPedWeapon( player, slot ) 
        if ( weapon > 0 ) then 
            local ammo = getPedTotalAmmo( player, slot ) 
            if ( ammo > 0 ) then 
                weapons[weapon] = ammo 
            end 
        end 
    end 
    return weapons 
end 
  
function playerJoinsEvent ( thePlayer, command ) 
    if ( eventStarted == true and not playersJoinedEvent[thePlayer] and command == "joinevent" ) then 
        local pX, pY, pZ = getElementPosition ( thePlayer ) 
        local randomobjectnumber = math.random(1, 300) 
        local playerSkin = getElementModel ( thePlayer ) 
        playersData[thePlayer] = 
            { 
                position = { pX, pY, pZ }, 
                skin = playerSkin, 
                weapons = convertPlayerWeaponsToTable( thePlayer ) 
            } 
        if spawnPlayer( thePlayer, adminPositionX, adminPositionY, adminPositionZ, 0, tonumber( skinID ) ) then 
            playerJoinedEvent = true 
            setElementModel ( thePlayer, randomobjectnumber ) 
            exports.global:giveWeapon ( thePlayer, weaponEvent, tonumber( weaponAmmo ) ) 
            outputChatBox( "#FFFFFFEVENT: You successfully joined the event", thePlayer, 255, 255, 255, true ) 
            playersJoinedEvent[thePlayer] = true 
        end 
        
    elseif ( eventStarted == false and not playersJoinedEvent[thePlayer] and command == "joinevent" ) then 
        outputChatBox( "#FFFFFFEVENT: There is no event currently ongoing.", thePlayer, 255, 255, 255, true ) 
    elseif ( eventStarted == true and playerJoinedEvent == true and command == "joinevent" ) then 
        outputChatBox( "#FFFFFFEVENT: You are already in the event", thePlayer, 255, 255, 255, true ) 
    end 
        
    if ( eventEnded == false and not playersJoinedEvent[thePlayer] and command == "endevent" ) then 
        loadOriginalData ( thePlayer ) 
        eventEnded = true 
    end 
  
    if ( command == "quitevent" and eventStarted == true and playersJoinedEvent[thePlayer] )then 
        --loadOriginalData ( thePlayer ) 
        killPed( thePlayer ) 
        outputChatBox( "#FFFFFFEVENT: You successfully quit the event.", thePlayer, 255, 255, 255, true ) 
    end 
end 
addCommandHandler("joinevent",playerJoinsEvent) 
addCommandHandler("quitevent",playerJoinsEvent) 
  
function loadOriginalData ( thePlayer ) 
    local savedData = playersData[thePlayer] 
    if ( savedData and type ( savedData ) == "table" ) then 
        local x, y, z = unpack ( savedData.position ) 
        playersJoinedEvent[thePlayer] = nil 
        local spawned = spawnPlayer( thePlayer, x, y, z, 0, savedData.skin) 
        if  (spawned ) then 
            takeAllWeapons ( thePlayer ) 
    
            for weapon, ammo in pairs ( savedData.weapons ) do 
                exports.global:giveWeapon ( thePlayer, weapon, ammo ) 
            end 
        end 
    end 
end 
  
function adminStartEvent(thePlayer, command, weaponId, ammoCMD) 
    if ( eventStarted == false and command == "startevent" and weaponId ~= null ) then 
        playersData = { } 
        playersJoinedEvent = { } 
        --Declaring booleans and variables 
        weaponAmmo = ammoCMD 
        weaponEvent = weaponId 
        eventEnded = false 
        eventStarted = true 
        local weaponName = getWeaponNameFromID ( weaponEvent ) 
        adminPositionX, adminPositionY, adminPositionZ = getElementPosition ( thePlayer ) 
        --*********************** 
        outputChatBox( "#FFFFFFEVENT: Event started by Admin", getRootElement( ), 255, 255, 255, true ) 
        outputChatBox( "#FFFFFFEVENT:  Weapon being used ".. weaponName, thePlayer,255, 255, 255, true ) 
    end 
    if ( eventStarted == false and command == "startevent" and weaponId == null ) then 
        outputChatBox( "SYNTAX: /startevent [weaponID] [ammo]", thePlayer, 255, 194, 14, true ) 
    end 
    if ( eventStarted == true and command == "endevent" ) then 
        eventStarted = false 
        eventEnded = true 
        playerJoinedEvent = false 
        outputChatBox( "#FFFFFFEVENT: Event ended by an Admin", thePlayer, 255, 255, 255, true ) 
    elseif ( eventStarted == false and command == "endevent" ) then 
        outputChatBox( "#FFFFFFEVENT: There is no event in progress.", thePlayer, 255, 255, 255, true ) 
    end 
end 
addCommandHandler( "startevent", adminStartEvent ) 
addCommandHandler( "endevent", adminStartEvent ) 
  
addEventHandler( "onPlayerSpawn", getRootElement( ), 
    function  ( ) 
        if ( eventStarted == true and playersJoinedEvent[source] ) then 
            loadOriginalData ( source ) 
        end 
    end 
) 
  
addEventHandler( "onPlayerWasted", getRootElement( ), 
    function  ( ) 
        if ( eventStarted == true and playerJoinedEvent == true ) then 
            loadOriginalData ( source ) 
        end 
    end 
) 
  

You mean it?

See line 177

If you type cmd /quitevent you killed and respawned.

help please

nono, that's the thing I want fixed :P if you die in event (onPlayerWasted) you get TPed back - loadOriginalData ( source )

and then you die after that. I'm trying to prevent that from happening. (You're not supposed to die after you get killed in event). You're just supposed to die in event and then go back to your normal position outside event without dieing

Can't I cancel the playerDeath event? like..

addEventHandler( "onPlayerWasted", getRootElement( ), 
    function  ( ) 
        if ( eventStarted == true and playerJoinedEvent == true ) then 
            loadOriginalData ( source ) 
            cancelEvent = playerDeath () 
        cancelEvent = respawnPlayer () 
        end 
    end 
) 
  

fixed

EDIT: I noticed something else <.<

if I /endevent, loadOriginalData ( source ) doesn't take effect. It just leaves me on the current spot with my "event guns".

This is what I got:

mysql = exports.mysql 
local prisonmarker = createMarker ( 187.14199829102, 1868.3699951172, 17.746978759766, "cylinder", 250, 0, 0, 0, 0, 0 )
function playerDeath()
        if (playerJoinedEvent == true) then
        cancelEvent (onPlayerWasted, playerDeath)
    if getElementData(source, "dbid") then
        local name = string.gsub(getPlayerName(source), "_", " ")
        local eventStarted = false
    local playersJoinedEvent = { }
    local weaponEvent, weaponAmmo, eventEnded
    local adminPositionX, adminPositionY, adminPositionZ
    local playersData = { }
        setPlayerNametagText(source, tostring(name))
        exports['anticheat-system']:changeProtectedElementDataEx(source, "nameTint", 0)
       
        if getElementData(source, "adminjailed" or eventStarted == true) then
            spawnPlayer(source, 263.821807, 77.848365, 1001.0390625, 270, getElementModel(source), 0, getElementData(source, "playerid")+65400, getPlayerTeam(source))
            setCameraInterior(source, 6)
            setCameraTarget(source)
            fadeCamera(source, true)
        else
            outputChatBox("Respawn in 5 seconds.", source)
            setTimer(respawnPlayer, 5000, 1, source)  
        end
        end
    end
end
addEventHandler("onPlayerWasted", getRootElement(), playerDeath)
 
function respawnPlayer(thePlayer)
        if (playerJoinedEvent == true) then
        cancelEvent (onPlayerWasted, playerDeath)
    if (isElement(thePlayer)) then
        local cost = 0
        local faction = false
        if not exports.global:isPlayerSilverDonator(thePlayer) then
            local team = getPlayerTeam(thePlayer)
            if getTeamName(team) == "San Andreas Network" then
                _, cost = exports.global:takeMoney(team, math.random(150, 300), true)
                faction = getTeamName(team)
            else
                _, cost = exports.global:takeMoney(thePlayer, math.random(150, 300), true)
            end
        end
       
        local tax = exports.global:getTaxAmount()
       
        exports.global:giveMoney( getTeamFromName("Las Venturas Emergency Services"), math.ceil((1-tax)*cost) )
        exports.global:giveMoney( getTeamFromName("Government of Los Santos"), math.ceil(tax*cost) )
           
        mysql:query_free("UPDATE characters SET deaths = deaths + 1 WHERE charactername='" .. mysql:escape_string(getPlayerName(thePlayer)) .. "'")
 
        setCameraInterior(thePlayer, 0)
           
        local text = "You have recieved treatment from the Los Santos Medical Center."
        if cost > 0 then
            text = text .. " Cost: " .. cost .. "$"
        end
        if faction then
            text = text .. ", paid by " .. faction .. "."
        end
        outputChatBox(text, thePlayer, 255, 255, 0)
       
        -- take all drugs
        local count = 0
        for i = 30, 43 do
            while exports.global:hasItem(thePlayer, i) do
                exports.global:takeItem(thePlayer, i)
                count = count + 1
            end
        end
        if count > 0 then
            outputChatBox("The illegal substances you had have been handed over to investigators.", thePlayer, 255, 194, 14)
        end
           
        local theSkin = getPedSkin(thePlayer)
           
        local theTeam = getPlayerTeam(thePlayer)
       
        local fat = getPedStat(thePlayer, 21)
        local muscle = getPedStat(thePlayer, 23)
           
        setPedStat(thePlayer, 21, fat)
        setPedStat(thePlayer, 23, muscle)
       
        spawnPlayer(thePlayer,1185.296875, -1323.7158203125, 13.572407722473, 0, theSkin, 0, 0, theTeam)
           
        fadeCamera(thePlayer, true, 6)
        triggerClientEvent(thePlayer, "fadeCameraOnSpawn", thePlayer)
    end
end
end
function deathRemoveWeapons(weapons, removedWeapons)
    setTimer(giveGunsBack, 10005, 1, source, weapons, removedWeapons)
end
addEvent("onDeathRemovePlayerWeapons", true)
addEventHandler("onDeathRemovePlayerWeapons", getRootElement(), deathRemoveWeapons)
 
function giveGunsBack(thePlayer, weapons, removedWeapons, removedWeapons2)
    if (removedWeapons~=nil) then
        if tonumber(getElementData(thePlayer, "license.gun")) == 0 and getElementData(getPlayerTeam(thePlayer),"type") ~= 2 then
        outputChatBox("The employees have taken away weapons which you did not have a license for. (" .. removedWeapons .. ").", thePlayer, 255, 194, 14)
        else
            outputChatBox("The employees have taken away weapons which you are not allowed to carry. (" .. removedWeapons .. ").", thePlayer, 255, 194, 14)
        end
    end
    if removedWeapons2 ~= nil then
        outputChatBox("The employees have taken away your " .. removedWeapons2 .. " for safety purposes.", thePlayer, 255, 194, 14)
    end
    -- 28
    for key, value in ipairs(weapons) do
        local weapon = tonumber(weapons[key][1])
        local ammo = tonumber(weapons[key][2])
        local removed = tonumber(weapons[key][3])
       
        if (removed==0) then
            exports.global:giveWeapon(thePlayer, weapon, math.floor( ammo / 2 ), false)
        else
            exports.global:takeWeapon(thePlayer, weapon)
            exports.logs:logMessage("[Death] " .. getElementData(thePlayer, "gameaccountusername") .. "/" .. getPlayerName(thePlayer) .. " lost a weapon (" .. getWeaponNameFromID (weapon) .. "/".. tostring(ammo) .." ammo)", 28)
        end
    end
end
 
 
local eventStarted = false
local playersJoinedEvent = { }
local weaponEvent, weaponAmmo, eventEnded
local adminPositionX, adminPositionY, adminPositionZ
local playersData = { }
 
 function convertPlayerWeaponsToTable(player)
    local weapons = { }
    for slot = 0, 12 do
        local weapon = getPedWeapon( player, slot )
        if ( weapon > 0 ) then
            local ammo = getPedTotalAmmo( player, slot )
            if ( ammo > 0 ) then
                weapons[weapon] = ammo
            end
        end
    end
    return weapons
end
 
function playerJoinsEvent ( thePlayer, command )
    if ( eventStarted == true and not playersJoinedEvent[thePlayer] and command == "joinevent") then
        local pX, pY, pZ = getElementPosition ( thePlayer )
        local randomobjectnumber = math.random(1, 300)
        local playerSkin = getElementModel ( thePlayer )
        playersData[thePlayer] =
            {
                position = { pX, pY, pZ },
                skin = playerSkin,
                weapons = convertPlayerWeaponsToTable( thePlayer )
            }
        if spawnPlayer( thePlayer, adminPositionX, adminPositionY, adminPositionZ, 0, tonumber( skinID ) ) then
            playerJoinedEvent = true
            setElementModel ( thePlayer, randomobjectnumber )
            exports.global:giveWeapon ( thePlayer, weaponEvent, tonumber( weaponAmmo ) )
            outputChatBox( "#FFFFFFEVENT: You successfully joined the event", thePlayer, 255, 255, 255, true )
            end
    if exports.global:isPlayerFullAdmin( thePlayer ) then
local playerName = getPlayerName(thePlayer)
        setElementModel ( thePlayer, 29 )
        setPlayerNametagText ( thePlayer, playerName .. " (ADMIN)" )
            playersJoinedEvent[thePlayer] = true
        end
    elseif ( eventStarted == false and not playersJoinedEvent[thePlayer] and command == "joinevent" ) then
        outputChatBox( "#FFFFFFEVENT: There is no event currently ongoing.", thePlayer, 255, 255, 255, true )
    elseif ( eventStarted == true and playerJoinedEvent == true and command == "joinevent" ) then
        outputChatBox( "#FFFFFFEVENT: You are already in the event", thePlayer, 255, 255, 255, true )
 
     end
     
    if (command == "endevent" and eventStarted == true and eventEnded == false and playersJoinedEvent[thePlayer]) then
        loadOriginalData ( thePlayer )
        eventEnded = true
    end
 
    if ( command == "quitevent" and eventStarted == true and playersJoinedEvent[thePlayer] )then
        loadOriginalData ( thePlayer )
        outputChatBox( "#FFFFFFEVENT: You successfully quit the event.", thePlayer, 255, 255, 255, true )
    end
end
addCommandHandler("joinevent",playerJoinsEvent)
addCommandHandler("quitevent",playerJoinsEvent)
addCommandHandler("endevent",playerJoinsEvent)
 
function loadOriginalData ( thePlayer )
    local savedData = playersData[thePlayer]
    if ( savedData and type ( savedData ) == "table" ) then
        local x, y, z = unpack ( savedData.position )
        playersJoinedEvent[thePlayer] = nil
        local spawned = spawnPlayer( thePlayer, x, y, z, 0, savedData.skin)
        if  (spawned ) then
            takeAllWeapons ( thePlayer )
   
            for weapon, ammo in pairs ( savedData.weapons ) do
                exports.global:giveWeapon ( thePlayer, weapon, ammo )
            end
        end
    end
end
 
function adminStartEvent(thePlayer, command, weaponId, ammoCMD)
    if ( eventStarted == false and command == "startevent" and weaponId ~= null ) then
        playersData = { }
        playersJoinedEvent = { }
        --Declaring booleans and variables
        weaponAmmo = ammoCMD
        weaponEvent = weaponId
        eventEnded = false
        eventStarted = true
        local weaponName = getWeaponNameFromID ( weaponEvent )
        adminPositionX, adminPositionY, adminPositionZ = getElementPosition ( thePlayer )
        --***********************
        outputChatBox( "#FFFFFFEVENT: Event started by Admin", getRootElement( ), 255, 255, 255, true )
        outputChatBox( "#FFFFFFEVENT:  Weapon used: ".. weaponName, thePlayer,255, 255, 255, true )
    end
    if ( eventStarted == false and command == "startevent" and weaponId == null ) then
        outputChatBox( "SYNTAX: /startevent [weaponID] [Ammo]", thePlayer, 255, 194, 14, true )
    end
    if ( eventStarted == true and command == "endevent" ) then
        eventStarted = false
        eventEnded = true
        playerJoinedEvent = false
        outputChatBox( "#FFFFFFEVENT: Event ended by an Admin", thePlayer, 255, 255, 255, true )
    elseif ( eventStarted == false and command == "endevent" ) then
        outputChatBox( "#FFFFFFEVENT: There is no event in progress.", thePlayer, 255, 255, 255, true )
    end
end
addCommandHandler( "startevent", adminStartEvent )
addCommandHandler( "endevent", adminStartEvent )
 
addEventHandler( "onPlayerSpawn", getRootElement( ),
    function  ( )
        if ( eventStarted == true and playersJoinedEvent[source] ) then
            loadOriginalData ( source )
        end
    end
    )
 
addEventHandler( "onPlayerWasted", getRootElement( ),
    function  ( )
        if ( eventStarted == true and playerJoinedEvent == true ) then
            loadOriginalData ( source )
        end
    end
)
 
 
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...