Cronoss Posted February 7, 2022 Share Posted February 7, 2022 I finished a script for respawn a couple hours ago. I tested it and I found an error, the second text should appear only for the player that it's dead, but it shows up to everybody. I've been trying figuring out why this "source" works in the function for other elements like "set animation", and the firts outputChat but I stilll don't know what happened... function revivir1() revivir = 1 cancelText = nil setPedAnimation(source, ".", ".", -1, false, false, false, true) outputChatBox (".", source, 255, 0, 0) setTimer(function () si = 1 cancelText = cancelText if (cancelText==nil) then outputChatBox(".", source, 255, 0, 0) ------This is the wrong text end end, 600, 1) end addEvent("sistemarev", true) addEventHandler("sistemarev", root, revivir1) As the title says, server-side part Link to comment
βurak Posted February 7, 2022 Share Posted February 7, 2022 (edited) give the source player to the timer like this function revivir1() revivir = 1 cancelText = nil setPedAnimation(source, ".", ".", -1, false, false, false, true) outputChatBox (".", source, 255, 0, 0) setTimer(function(source) -- Pass source player into timer si = 1 cancelText = cancelText if (cancelText==nil) then outputChatBox(".", source, 255, 0, 0) ------This is the wrong text end end, 600, 1, source) -- Pass source player into timer end addEvent("sistemarev", true) addEventHandler("sistemarev", root, revivir1) Edited February 7, 2022 by Burak5312 1 Link to comment
Cronoss Posted February 7, 2022 Author Share Posted February 7, 2022 Similar problem is here, but this time the command works for every player intead of the source player, how could I fix this? function revivir(source) if (si==1) and (cancelText==nil) then spawnPlayer(source, 2041.3568115234,-1409.2247314453,17.1640625,178) si = 0 takePlayerMoney(source, 1000) takeAllWeapons(source) outputChatBox("...", source, 0, 255, 0) end end addCommandHandler("test", revivir) Link to comment
๖ۣۜζ͜͡RapGod Posted February 7, 2022 Share Posted February 7, 2022 Hey, try adding the command as a parameter to the function aswell. I'm not sure if it will work like this, but i always do it when i add a command. Example: function revivir(source,cmd) --the code here. end addCommandHandler("test",revivir) If i'm wrong then feel free to correct me. Maybe i'd learn some things myself. Link to comment
Cronoss Posted February 8, 2022 Author Share Posted February 8, 2022 (edited) Didn't work, I found the error, the thing is that the command is in server side, so all the conditionals I added are in the SERVER, every player can start the function. Isn't there any way to make that just a specific player can make the function to work? This is a Respawn system, so I'm needing that just the player who types the command can make it run: function revivir1() revivir = 1 ------ 1 cancelText = nil ---------2 setPedAnimation(source, ".", ".", -1, false, false, false, true) outputChatBox (".", source, 255, 0, 0) setTimer(function(source) si = 1 ------------- 3 cancelText = cancelText if (cancelText==nil) then outputChatBox(".", source, 255, 0, 0) end end, 600, 1, source) end addEvent("sistemarev", true) addEventHandler("sistemarev", root, revivir1) And then: function morir (source) if not(revivir==1) then -------------conditional cancelText = 1 spawnPlayer(source, 2041.3568115234,-1409.2247314453,17.1640625,178) si = 0 takePlayerMoney(source, 1000) takeAllWeapons(source) outputChatBox("", source, 0, 255, 0) end end addEvent("morir", true) addEventHandler("morir", root, morir) PD: Checking his(her health doesn't work for me because I made a "knoc down" function that sets the player life back in 100 Edited February 8, 2022 by Cronoss Link to comment
βurak Posted February 8, 2022 Share Posted February 8, 2022 (edited) you can use a table for this, when you bring back the player's health, you mark it as true in this table, you change it to false when it spawns again so it only uses knocked down players setPlayerKnockDown(player, true) --mark the player as knocked down so he can use the command local isPlayersKnockDown = {} function setPlayerKnockDown(player, condition) isPlayersKnockDown[player] = condition end function revivir(source) if (si==1) and (cancelText==nil) then if(isPlayersKnockDown[source]) then -- only downed players can use spawnPlayer(source, 2041.3568115234,-1409.2247314453,17.1640625,178) si = 0 takePlayerMoney(source, 1000) takeAllWeapons(source) outputChatBox("...", source, 0, 255, 0) setPlayerKnockDown(source, false) --set false when the player spawns so he can't use it again end end end addCommandHandler("test", revivir) addEventHandler("onPlayerQuit", root, function() isPlayersKnockDown[source] = nil -- clean from memory end ) Edited February 8, 2022 by Burak5312 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now