Jump to content

outputChatBox doesn't work (server-side)


Cronoss

Recommended Posts

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

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 by Burak5312
  • Thanks 1
Link to comment

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

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 by Cronoss
Link to comment

 

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