Jump to content

spawnPlayer don't work :C


Loren_ita

Recommended Posts

rootElement = getRootElement ()
players = getElementsByType("player")  -- <----
 
function startMap( startedMap )
   mapRoot = getResourceRootElement( startedMap )
triggerEvent ( "PlayerSpawn", rootElement, players ) -- <----
end

Note how you're sending a table of players to a function that will only accept a single player argument. spawnPlayer simply doesn't like this, and when scripting functions don't like something, they won't give you the desired results.

To fix this we need to split the table and trigger the event for every player. Much like:

for index, player in ipairs(players) do -- For every entry in indexed table "players", store the index in variable "index", and the value in variable "player"
triggerEvent ( "PlayerSpawn", rootElement, player ) -- Trigger event "PlayerSpawn" with source "rootElement" and 1st argument is the value of variable "player"
end -- End of the code that has to be executed for every entry

Note: You can remove the "--" and the text behind it, however leaving them there causes no harm. They're comments, and Lua will just skip these when the script executes. ;)

I hope that'll fix it for you.

Link to comment

Thanks. Now the script don't have error but it don't spawn me. i don't understand...

I write here the script for any help:

--RTKI GAMEMODE by Loren_ita
rootElement = getRootElement ()
players = getElementsByType("player")
 
 
function startMap( startedMap )
mapRoot = getResourceRootElement( startedMap )
 for index, player in ipairs(players) do -- For every entry in indexed table "players", store the index in variable "index", and the value in variable "player"
   triggerEvent( "PlayerSpawn", rootElement, player ) -- Trigger event "PlayerSpawn" with source "rootElement" and 1st argument is the value of variable "player"
 end
end
 
addEvent ( "PlayerSpawn", true )
 
function joinHandler( thePlayer  )
local SpawnElements = getElementsByType ( "spawnpoint", mapRoot )
local value = SpawnElements[math.random(#SpawnElements)]
local x = tonumber( getElementData( value, "posX" ) )
local y = tonumber( getElementData( value, "posY" ) )
local z = tonumber( getElementData( value, "posZ" ) )
local r = tonumber( getElementData( value, "rotZ" ) or 0 )
repeat until spawnPlayer ( thePlayer , x, y, z, r, math.random (0,288))
 
end
 
function respawndied()
setTimer( joinHandler, 1800, 1, source )
end
 
function spawnJoin()
setTimer( joinHandler, 1800, 1, source )
end
 
addEventHandler ("PlayerSpawn", rootElement, joinHandler)
addEventHandler ("onGamemodeMapStart", getRootElement(), startMap)
addEventHandler ("onPlayerWasted", getRootElement(), respawndied )
addEventHandler ("onPlayerJoin", getRootElement(), spawnJoin )

Link to comment

I also notice you're forgetting 2 camera related things:

- Camera is faded to black by default

- Camera isn't aiming at the player by default

To fix the above 2 "problems", use:

fadeCamera(thePlayer,true) -- The player can see now, but it's kind of in a useless spot
setCameraTarget(thePlayer,thePlayer) -- The camera is now following the player, which is a lot more useful

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