Jump to content

client = source?


DexoTronic

Recommended Posts

Hi

i have a problem.

i have this client script:

function onClickBtn ( button, state )
if (button == "left" and state == "up") then
	if (source == TruckArbeitBtn ) then
		guiSetInputEnabled(false)
		guiSetVisible ( TruckWindow , false )
		showCursor ( false )
		triggerServerEvent (  "truckerarbeit", getRootElement())
	end
end
end
 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), windowHandler )
addEventHandler ( "onClientGUIClick", TruckArbeitBtn, onClickBtn, false )

it triggers the server event "truckarbeit"

:

function truckerarbeit_func ( )
if PlayerJob[client] < 2 or PlayerJob[client] > 2 then
	outputChatBox( "Du musst erst den Job annehmen!", client, 255, 0, 0 )
end
if PlayerJob[client] == 2 then
	Truck[client] = createVehicle( 455, -138.103515625, 1084.078125, 20.312187194824)
	setVehicleColor ( Truck[client], 3, 3, 3, 3 )
	warpPedIntoVehicle ( client, Truck[client] )
end
end
addEvent ( "truckerarbeit", true )
addEventHandler ( "truckerarbeit", getRootElement(), truckerarbeit_func )

works. perfectly. it creates the vehicle and puts the player in it.

now i want to delete the vehicle after the player leaves it:

(in the server script)

function exitVehicle ( theVehicle, seat, jacked )
if ( theVehicle == Truck[source]) then
	destroyElement(Truck[source])
 
 
end	
end
addEventHandler ( "onVehicleExit", getRootElement(), exitVehicle )

it doesnt work. i tried it with Truck[client] too, doesnt work too.

whats wrong?

Link to comment

the variable 'client' only exists in events that were triggered from a clientside script

if you look at the wiki page for onVehicleExit, the 'source' variable is actually the vehicle that was exited, not the player that got out. the player is passed as the first argument, so you need to do:

function exitVehicle ( thePlayer, seat, jacked )
if ( theVehicle == Truck[thePlayer]) then
destroyElement(Truck[thePlayer])
end   
end
addEventHandler ( "onVehicleExit", getRootElement(), exitVehicle )

Link to comment
function exitVehicle ( thePlayer, seat, jacked )
if ( source == Truck[thePlayer]) then
destroyElement(Truck[thePlayer])
end   
end
addEventHandler ( "onVehicleExit", getRootElement(), exitVehicle )

Corrected a small mistake in line 2: R3mp was still using theVehicle instead of source. :P

Link to comment

Hm...you should add some more Parameters to your trigger (Clientside) Command.

Try this...

function truckerarbeit_func ( client )
if PlayerJob[client] < 2 or PlayerJob[client] > 2 then
outputChatBox( "Du musst erst den Job annehmen!", client, 255, 0, 0 )
end
if PlayerJob[client] == 2 then
     Truck[client] = createVehicle( 455, -138.103515625, 1084.078125, 20.312187194824)
setVehicleColor ( Truck[client], 3, 3, 3, 3 )
warpPedIntoVehicle ( client, Truck[client] )
end
end
addEvent ( "truckerarbeit", true )
addEventHandler ( "truckerarbeit", getRootElement(), truckerarbeit_func )

triggerServerEvent (  "truckerarbeit", getRootElement(), getLocalPlayer())

What exactly is not working ?

Link to comment

Try it out, cause the Wikipedia says you need to work with 'source'

instead of 'client'. But ive you says you tryed them out, and they dont work, try to pass the PlayerElement to a Argument and it should work.

(It works for me, why not for ya :shock: )

Or something is going wrong with your Truck table.

I cant find any Bug in Gamesnerts Code aswell.

The 'onVehicleEnter' Handler is not the culprit :roll:

@Antibird

What are you trying to do ?

Printing a Element ?

Link to comment

What are you trying to do ?

Printing a Element ?

Exactly. Should output something like "userdata: [some hexadecimal number]".

If one hex is not equal to another one then " if ( source == Truck[thePlayer]) " condition won't ever become true.

By the way, why not to have a check:

function exitVehicle ( thePlayer, seat, jacked )
if ( source == Truck[thePlayer]) then
outputChatBox( "must be correct!" )
local success = destroyElement(Truck[thePlayer])
if sucess then
outputChatBox( "vehicle destroyed" )
end
else
outputChatBox( "Epic fail" )
end   
end
addEventHandler ( "onVehicleExit", getRootElement(), exitVehicle )

or something like that. Come on, fill up your code with debug strings. It always helps. How can you fix the error if you have no idea where it's located? I don't see anything wrong with Gamesnerts code neither.

Link to comment

It's obvious that "source" is not equal to "Truck[thePlayer]" in the "exit" event. But since you say "truckerarbeit_func" does the job just great and there are no any errors/warnings in server console, then I can't tell you what's wrong, I can't see the reason. It's something related to the rest code you have, most likely some mess with "Truck" table. Use debug strings throughout the code, check it line by line. Either post everything here if you like so.

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