Jump to content

[HELP] Why not working this script?


Turbe$Z

Recommended Posts

Client:

function winnerMessenger ( text, playerName)
    win.text = text
    win.name = playerName
	removeEventHandler("onClientRender",root,winMsg)
	addEventHandler("onClientRender",root,winMsg)
triggerServerEvent("plusz1", localPlayer, getLocalPlayer)
end
addEvent("winnerMessage",true)
addEventHandler("winnerMessage",getRootElement(),winnerMessenger)

Server:

function asdasd()
if getPlayerRank( source ) ~= 1 then return end
local gyozelmek = getElementData(source,"Győzelmek") or 0
setElementData(source, "Győzelmek", gyozelmek + 1 )
givePlayerMoney(source,2)
outputChatBox("#FFffFFAmiért megnyerted a kört, kaptál #00FFFF'2' coint!",source,r,g,b,true)
end
addEvent("plusz1", true)
addEventHandler("plusz1", root, asdasd)

And when the win msg appear, the setelementdata add 1 win point, and money for everybody.. How to fix this? I want add win point and money only to the winner, not everybody...

Link to comment
function winnerMessenger ( text, playerName)
    win.text = text
    win.name = playerName
	removeEventHandler("onClientRender",root,winMsg)
	addEventHandler("onClientRender",root,winMsg)
triggerServerEvent("plusz1", localPlayer)
end
addEvent("winnerMessage",true)
addEventHandler("winnerMessage", root, winnerMessenger)
function asdasd()
    if isElement(source) and source == client then
        if getPlayerRank( source ) ~= 1 then return end
            local gyozelmek = getElementData(source,"Győzelmek") or 0
            setElementData(source, "Győzelmek", gyozelmek + 1 )
            givePlayerMoney(source,2)
            outputChatBox("#FFffFFAmiért megnyerted a kört, kaptál #00FFFF'2' coint!",source,r,g,b,true) -- if you want messsage apear to everybody change the source to root thats all
		end
	end
end
addEvent("plusz1", true)
addEventHandler("plusz1", root, asdasd)

try this

Edited by Dimos7
Link to comment
5 minutes ago, Dimos7 said:

function winnerMessenger ( text, playerName)
    win.text = text
    win.name = playerName
	removeEventHandler("onClientRender",root,winMsg)
	addEventHandler("onClientRender",root,winMsg)
triggerServerEvent("plusz1", localPlayer)
end
addEvent("winnerMessage",true)
addEventHandler("winnerMessage", root, winnerMessenger)

function asdasd()
    if isElement(source) and source == client then
        if getPlayerRank( source ) ~= 1 then return end
            local gyozelmek = getElementData(source,"Győzelmek") or 0
            setElementData(source, "Győzelmek", gyozelmek + 1 )
            givePlayerMoney(source,2)
            outputChatBox("#FFffFFAmiért megnyerted a kört, kaptál #00FFFF'2' coint!",source,r,g,b,true) -- if you want messsage apear to everybody change the source to root thats all
		end
	end
end
addEvent("plusz1", true)
addEventHandler("plusz1", root, asdasd)

try this

same problem

Link to comment

It's just wrong, I suppose that winnerMessage gets triggered for everyone, right? So then everyone triggers plusz1, you're checking for getPlayerRank but I can't see how does that work. But it makes no sense to go from server to client and then back to the server.. you should add the points and money wherever winnerMessage is initially triggered.

Link to comment
1 minute ago, MIKI785 said:

It's just wrong, I suppose that winnerMessage gets triggered for everyone, right? So then everyone triggers plusz1, you're checking for getPlayerRank but I can't see how does that work. But it makes no sense to go from server to client and then back to the server.. you should add the points and money wherever winnerMessage is initially triggered.

I tried trigger from destructionderby.lua, but not solve it the problem.. :s

Link to comment
5 minutes ago, MIKI785 said:

Put it wherever winnerMessage is, since that knows who the player is as it supplies the player's name.

function DestructionDerby:handleFinishActivePlayer(player)
	local timePassed = self:getTimePassed()
	local rank = self:getPlayerRank(player)
	if rank >= 2 then
			triggerClientEvent("winnerMessage",resourceRoot,"Winner!!!", getPlayerNametagText(player))
			triggerEvent("plusz1", player)
	end
	finishActivePlayer(player)
	if rank and rank > 1 then
		triggerEvent( "onPlayerFinishDD",player,tonumber( rank ) )
	end
	local activePlayers = getActivePlayers()
	triggerEvent("onPlayerDeadInRace",getRootElement(),rank,player)
	if #activePlayers == 1 then
		if (not isMapDM()) then 
		    if getResourceState( getResourceFromName( "podium" )) ~= "running" then
		        triggerClientEvent("winnerMessage",resourceRoot,"Winner!!!", getPlayerNametagText(activePlayers[1]))
			else
                triggerClientEvent("winnerMessage",resourceRoot,"","")	
				setElementHealth(activePlayers[1],0)
			end	
		end
		if getElementModel(getPedOccupiedVehicle(activePlayers[1])) == 425 then
			setElementHealth(activePlayers[1],0)
		end
		triggerEvent( "onPlayerWinDD",activePlayers[1] )
	end
end

i putted in this function, but does not working at all.. :s 

Link to comment

But you have it under if  rank >= 2 then, so how can that work? Isn't it supposed to be for the first player? Ie. rank 1?
There's another case where that event is triggered, so try it there:
 

function DestructionDerby:handleFinishActivePlayer(player)
	local timePassed = self:getTimePassed()
	local rank = self:getPlayerRank(player)
	if rank >= 2 then
			triggerClientEvent("winnerMessage",resourceRoot,"Winner!!!", getPlayerNametagText(player))
			triggerEvent("plusz1", player)
	end
	finishActivePlayer(player)
	if rank and rank > 1 then
		triggerEvent( "onPlayerFinishDD",player,tonumber( rank ) )
	end
	local activePlayers = getActivePlayers()
	triggerEvent("onPlayerDeadInRace",getRootElement(),rank,player)
	if #activePlayers == 1 then
		if (not isMapDM()) then 
		    if getResourceState( getResourceFromName( "podium" )) ~= "running" then
		        triggerClientEvent("winnerMessage",resourceRoot,"Winner!!!", getPlayerNametagText(activePlayers[1]))
        		triggerEvent("plusz1", activePlayers[1]) --Here
			else
                triggerClientEvent("winnerMessage",resourceRoot,"","")	
				setElementHealth(activePlayers[1],0)
			end	
		end
		if getElementModel(getPedOccupiedVehicle(activePlayers[1])) == 425 then
			setElementHealth(activePlayers[1],0)
		end
		triggerEvent( "onPlayerWinDD",activePlayers[1] )
	end
end

 

  • Thanks 1
Link to comment
5 minutes ago, MIKI785 said:

But you have it under if  rank >= 2 then, so how can that work? Isn't it supposed to be for the first player? Ie. rank 1?
There's another case where that event is triggered, so try it there:
 


function DestructionDerby:handleFinishActivePlayer(player)
	local timePassed = self:getTimePassed()
	local rank = self:getPlayerRank(player)
	if rank >= 2 then
			triggerClientEvent("winnerMessage",resourceRoot,"Winner!!!", getPlayerNametagText(player))
			triggerEvent("plusz1", player)
	end
	finishActivePlayer(player)
	if rank and rank > 1 then
		triggerEvent( "onPlayerFinishDD",player,tonumber( rank ) )
	end
	local activePlayers = getActivePlayers()
	triggerEvent("onPlayerDeadInRace",getRootElement(),rank,player)
	if #activePlayers == 1 then
		if (not isMapDM()) then 
		    if getResourceState( getResourceFromName( "podium" )) ~= "running" then
		        triggerClientEvent("winnerMessage",resourceRoot,"Winner!!!", getPlayerNametagText(activePlayers[1]))
        		triggerEvent("plusz1", activePlayers[1]) --Here
			else
                triggerClientEvent("winnerMessage",resourceRoot,"","")	
				setElementHealth(activePlayers[1],0)
			end	
		end
		if getElementModel(getPedOccupiedVehicle(activePlayers[1])) == 425 then
			setElementHealth(activePlayers[1],0)
		end
		triggerEvent( "onPlayerWinDD",activePlayers[1] )
	end
end

 

Thank you! :DDD

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