TimJ Posted January 23, 2009 Posted January 23, 2009 The one thing i havnt really done in scripting is spawning players and its just not working out for me. Heres the code: function greetPlayer ( ) local joinedPlayerName = getClientName ( source ) outputChatBox ( "Welcome, " .. joinedPlayerName .. " please login or register." , source, 255, 255, 255 ) spawnPlayer ( playerValue, 0.0, 0.0, 5.0, 90.0, 0 ) end addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer ) it just says bad argument on the spawn player line. Any help will be much appreciated
Mr.Hankey Posted January 23, 2009 Posted January 23, 2009 where is playerValue definied? use source instead
TimJ Posted January 24, 2009 Author Posted January 24, 2009 I dont know why it said player value in there lol, but i changed it to Source and still the same problem : [11:11:48] WARNING: playerjoin.lua: Bad argument @ 'spawnPlayer' - Line: 8
[UVA]Bart Posted January 24, 2009 Posted January 24, 2009 function greetPlayer (source ) local joinedPlayerName = getClientName ( source ) outputChatBox ( "Welcome, " .. joinedPlayerName .. " please login or register." , source, 255, 255, 255 ) spawnPlayer ( source, 0.0, 0.0, 5.0, 90.0, 0 ) end addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer )
TimJ Posted January 24, 2009 Author Posted January 24, 2009 Sorry, just realised i had "Source" not "source" that was stupid of me... oh well ill use this post when i run in to my next problem. Thanks for all your time.
TimJ Posted January 24, 2009 Author Posted January 24, 2009 OK, i've hit my next problem. Heres the new code: function greetPlayer ( ) local joinedPlayerName = getClientName ( source ) outputChatBox ( "Welcome, " .. joinedPlayerName .. " please login or register." , source, 255, 255, 255 ) end addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer ) function spawnMe () fadeCamera ( source, true, 1.0, 0, 0, 0 ) bindKey ( source, "1", "down", spawn1 ) end addEventHandler("onClientLogin",getRootElement(),spawnMe) function spawn1 () spawnPlayer ( source, 0.0, 0.0, 5.0, 90.0, 0 ) end It's telling me theres a bad argument on the spawn player again, but this is the same as it was when it worked and they spawned straight when they logged in WARNING: playerjoin.lua: Bad argument @ 'spawnPlayer' - Line:28
darkdreamingdan Posted January 24, 2009 Posted January 24, 2009 bindKey handler functions dont have a source. It does however have some default parameters attached to the handler function: function spawn1 (player,key,keyState) spawnPlayer ( player, 0.0, 0.0, 5.0, 90.0, 0 ) end
TimJ Posted January 24, 2009 Author Posted January 24, 2009 I have yet another problem with binds, this time its unbind problem: function onSpawn ( source ) unbindKey ( source, "1", "down", spawn1 ) end addEventHandler ( "onPlayerSpawn", getRootElement(), onSpawn ) it gives me bad argument... (by the way this is in the same file as the other stuff)
50p Posted January 24, 2009 Posted January 24, 2009 DO NOT USE source AS A PARAMETER!!! MTA made it so complicated for noobs -.-' What does "source" mean? Does it mean "player"? Does it mean "vehicle"? NO! It's a "secret" variable that is passed to a function when events occur. If it's "onPlayer..." then source will be "player", when it's "onVehicle..." then source will be "vehicle". Why do you use "source" in argument list of function? You should use other variable names... if you expect there to be a player call it player, if vehicle, call it vehicle, etc... Keep away from source in argument list!
jkub Posted January 25, 2009 Posted January 25, 2009 thePlayer = getLocalPlayer()[/code ] ??? can that replace source?
[DKR]silverfang Posted January 25, 2009 Posted January 25, 2009 thePlayer = getLocalPlayer()[/code ] ??? can that replace source?getLocalPlayer() only works in client side scripts...
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