Jump to content

The most nooby stupid question


TimJ

Recommended Posts

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 :)

Link to comment
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 ) 

Link to comment

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 :S

WARNING: playerjoin.lua: Bad argument @ 'spawnPlayer' - Line:28 

Link to comment

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)

Link to comment

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!

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