Jump to content

Help with function triggerServerEvent!


JustDance

Recommended Posts

Posted (edited)

Hello community MTA. I have a problem with the function triggerServerEvent. First you all worked fine, but now I began to write a new game mode and I did not cause triggerServerEvent function from the server.

For example, I even take a simple example from the documentation:

Server:

function greetingHandler ( message )
outputChatBox ( "The client says: " .. message, source )
end
addEvent( "onGreeting", true )
addEventHandler( "onGreeting", getRootElement(), greetingHandler )

Client:

function greetingCommand ( commandName )
triggerServerEvent ( "onGreeting", getLocalPlayer(), "Hello World!" ) 
-- getLocalPlayer instead of getRootElement makes the client player the 'source' on the server function, eliminating the need for an additional player argument to be transferred.
end
addCommandHandler ( "greet", greetingCommand )

(In game write command /greet)

In the console wrote:

[08:59:36] ERROR: Client triggered serverside event onGreeting, but event is not added serverside

In meta.xml everything correctly written:

 
<meta>
<info author="JustDance" description="San fierro Team Death Match" version="0.1" type="gamemode" />	
<script src="sftdm.lua" type="server"/>
<script src="sftdm_client.lua" type="client"/>	
<file src="img/buttom_left.png" />
</meta>
 

Please help me :(

Edited by Guest
Posted

i think that's not whole code, so

something BEFORE your event add in the server script make script stop at one moment..

check the server console for errors.

everything else looks ok after looking for 1 min

Posted

All code:

Server:

teamInfo = {
{"Workers", 260, {-2058.9489746094, 239.52754211426, 35.429023742676, 270}},
{"Mechanics", 50, {-2046.4837646484, -99.515892028809, 35.1640625, 0}},
{"Valets", 189, {-1754.2215576172, 960.12322998047, 24.8828125, 180}},
{"Cops", 280, {-1638.8996582031, 665.20745849609, 7.1875, 260}},
{"FBI", 286, {-1913.5079345703, 486.71041870117, 35.171875, 90}},
{"Medics", 274, {-2637.66015625, 610.41967773438, 14.453125, 180}},
{"Bikers", 248, {-1498.7154541016, 920.1044921875, 7.1875, 90}},
{"Army", 287, {-1309.4479980469, 436.12585449219, 7.1875, 0}}
}
 
function onResourceStart()
createTeam(teamInfo[1][1], 123, 186, 97)
createTeam(teamInfo[2][1], 123, 186, 97)
end
addEventHandler ( "onResourceStart", getRootElement(), onResourceStart )
 
function spawn(last)
outputChatBox{"lol", source)
spawnPlayer(teamInfo[last][2], teamInfo[last][3][1], teamInfo[last][3][2], teamInfo[last][3][3])
setCameraTarget(source, source)
end
addEvent("spawn",true)
addEventHandler("spawn",getRootElement(),spawn)
 
function greetingHandler ( message )
outputChatBox ( "The client says: " .. message, source )
end
addEvent( "onGreeting", true )
addEventHandler( "onGreeting", getRootElement(), greetingHandler )

Client:

teamInfo = {
{"Workers", 260, {-2058.9489746094, 239.52754211426, 35.429023742676, 270}},
{"Mechanics", 50, {-2046.4837646484, -99.515892028809, 35.1640625, 0}},
{"Valets", 189, {-1754.2215576172, 960.12322998047, 24.8828125, 180}},
{"Cops", 280, {-1638.8996582031, 665.20745849609, 7.1875, 260}},
{"FBI", 286, {-1913.5079345703, 486.71041870117, 35.171875, 90}},
{"Medics", 274, {-2637.66015625, 610.41967773438, 14.453125, 180}},
{"Bikers", 248, {-1498.7154541016, 920.1044921875, 7.1875, 90}},
{"Army", 287, {-1309.4479980469, 436.12585449219, 7.1875, 0}}
}
 
last = 1
 
function selectPlayer()
fadeCamera(true)
showChat(true)
setCameraMatrix(-2004.2983398438, 274.61813354492, 32.900520324707, -2003.24609375, 340.98733520508, 55.439319610596)
sPed = createPed(teamInfo[1][2], -2004.26171875, 277.08142089844, 33.361419677734)
showPlayerHudComponent("radar", false)
showPlayerHudComponent("area_name", false)
bindKey("arrow_r", "down", nextped_r)
bindKey("arrow_l", "down", nextped_l)
bindKey("lshift", "down", spawn)
bindKey("enter", "down", spawn)
setPedRotation ( sPed, 180 )
img1 = guiCreateStaticImage( 0, 460, 644, 595, "img/buttom_left.png", false )
end
 
------------------------------------------------------------------------------------------------------------------------
 
function nextped_r()
if	last == 8	then
	last = 1
setPedSkin(sPed, teamInfo[last][2])
else	
	last = last + 1
setPedSkin(sPed, teamInfo[last][2])
end
end	
function nextped_l()
if	last == 1	then
	last = 8
setPedSkin(sPed, teamInfo[last][2])
else
	last = last - 1
setPedSkin(sPed, teamInfo[last][2])
end	
end
function spawn()
unbindKey("arrow_r", "down", nextped_r)
unbindKey("arrow_l", "down", nextped_l)
unbindKey("lshift", "down", spawn)
unbindKey("enter", "down", spawn)
skin = teamInfo[last][2]
guiSetVisible ( img1, false )
destroyElement(sPed)
triggerServerEvent ( "onGreeting", getLocalPlayer(), "Hello World!" ) 
showChat(true)
end		
 
------------------------------------------------------------------------------------------------------------------------
 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
function()
	selectPlayer()
end
)
 
function greetingCommand ( commandName )
triggerServerEvent ( "onGreeting", getLocalPlayer(), "Hello World!" ) 
-- getLocalPlayer instead of getRootElement makes the client player the 'source' on the server function, eliminating the need for an additional player argument to be transferred.
end
addCommandHandler ( "greet", greetingCommand )

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