Jump to content

spawnPlayer don't work :C


Loren_ita

Recommended Posts

I'm creating a new gamemode. For now it is a test. But if it work i complete it. The spawnplayer function don't work... all work but it don't work.

The gamemode have the editor definitions and that works.

--RTFI GAMEMODE by Loren_ita
 
rootElement = getRootElement ()
 
function startMap( startedMap )
 mapRoot = getResourceRootElement( startedMap )
 triggerEvent ( "PlayerSpawn", rootElement )
end
 
addEvent ( "PlayerSpawn", true )
 
function joinHandler( thePlayer  )
 local SpawnElements = getElementsByType ( "spawnpoint", mapRoot )
for key, value in pairs(SpawnElements) do
      x = getElementData( value, "posX" )
      y = getElementData( value, "posY" )
      z = getElementData( value, "posZ" )
      r = getElementData( value, "rot" ) or 0
    end
   spawnPlayer ( thePlayer , x, y, z, r, math.random (0,288))
end
 
function respawndied()
   setTimer( joinHandler, 1800, 1 )
end
 
function spawnJoin()
   setTimer( joinHandler,1000, 1 )
end
 
addEventHandler ("PlayerSpawn", rootElement, joinHandler)
addEventHandler ("onGamemodeMapStart", getRootElement(), startMap)
addEventHandler ("onPlayerWasted", getRootElement(), respawndied )
addEventHandler ("onPlayerJoin", getRootElement(), spawnJoin )

EDF:

<def name="RTFI">
<element name="spawnpoint" friendlyname="Spawnpoint" icon="edf/Spawn.png">
	<data name="position" type="coord3d" default="0,0,0" />
	<data name="rotation" type="coord3d" default="0,0,0" />
	<ped model="0" rotation="!rotation!"/>
    </element>
</def>

map:

<map edf:definitions="RTFI,editor_main">
   <vehicle id="Vehicle" paintjob="3" model="411" plate="MXHBTL6" interior="0" dimension="0" color="117,0,0,0" posX="2719.7392578125" posY="-1643.6375732422" posZ="12.802456855774" rotX="0" rotY="0" rotZ="0" upgrades="1010,1075" />
   <vehicle id="vehicle (Infernus) (1)" paintjob="3" model="411" plate="G5GFGNF" interior="0" dimension="0" color="117,0,0,0" posX="2725.7556152344" posY="-1643.2039794922" posZ="12.79462146759" rotX="0" rotY="0" rotZ="0" upgrades="1010,1075" />
   <vehicle id="vehicle (Infernus) (2)" paintjob="3" model="411" plate="CG8L4OV" interior="0" dimension="0" color="117,0,0,0" posX="2734.6540527344" posY="-1642.7683105469" posZ="12.783110618591" rotX="0" rotY="0" rotZ="0" upgrades="1010,1075" />
   <vehicle id="vehicle (Infernus) (3)" paintjob="3" model="411" plate="D3GYWPB" interior="0" dimension="0" color="117,0,0,0" posX="2740.4038085938" posY="-1642.7053222656" posZ="12.800790786743" rotX="0" rotY="0" rotZ="0" upgrades="1010,1075" />
   <vehicle id="vehicle (Infernus) (4)" paintjob="3" model="411" plate="2TOSWN6" interior="0" dimension="0" color="117,0,0,0" posX="2713.3972167969" posY="-1654.9931640625" posZ="12.870312690735" rotX="0" rotY="0" rotZ="89.72998046875" upgrades="1010,1075" />
   <vehicle id="vehicle (Infernus) (5)" paintjob="3" model="411" plate="VFP260I" interior="0" dimension="0" color="117,0,0,0" posX="2713.5734863281" posY="-1660.0007324219" posZ="12.870312690735" rotX="0" rotY="0" rotZ="89.725341796875" upgrades="1010,1075" />
   <marker id="Destination1" type="cylinder" color="#22DC5B99" size="0.69999998807907" interior="0" dimension="0" posX="527.50653076172" posY="-1354.2331542969" posZ="24.944387435913" rotX="0" rotY="0" rotZ="0" />
   <pickup id="pickup (M4) (1)" type="31" interior="0" amount="100" respawn="30000" dimension="0" posX="2716.8015136719" posY="-1648.6339111328" posZ="13.224266052246" rotX="0" rotY="0" rotZ="0" />
   <pickup id="pickup (M4) (2)" type="31" interior="0" amount="100" respawn="30000" dimension="0" posX="2714.6433105469" posY="-1650.72265625" posZ="13.228872299194" rotX="0" rotY="0" rotZ="0" />
   <pickup id="pickup (M4) (3)" type="31" interior="0" amount="100" respawn="30000" dimension="0" posX="2730.30078125" posY="-1643.4442138672" posZ="13.161993980408" rotX="0" rotY="0" rotZ="0" />
   <pickup id="pickup (M4) (4)" type="31" interior="0" amount="100" respawn="30000" dimension="0" posX="2744.3552246094" posY="-1648.1477050781" posZ="13.267062187195" rotX="0" rotY="0" rotZ="0" />
   <pickup id="pickup (M4) (5)" type="31" interior="0" amount="100" respawn="30000" dimension="0" posX="2746.1059570313" posY="-1650.6162109375" posZ="13.281139373779" rotX="0" rotY="0" rotZ="0" />
   <pickup id="pickup (M4) (6)" type="31" interior="0" amount="100" respawn="30000" dimension="0" posX="2714.8037109375" posY="-1665.8974609375" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <pickup id="pickup (M4) (7)" type="31" interior="0" amount="100" respawn="30000" dimension="0" posX="2714.150390625" posY="-1663.9611816406" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (1)" interior="0" posX="2740.2175292969" posY="-1664.3984375" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (2)" interior="0" posX="2738.271484375" posY="-1664.3308105469" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (3)" interior="0" posX="2736.3493652344" posY="-1664.5023193359" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (4)" interior="0" posX="2734.1662597656" posY="-1664.4000244141" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (5)" interior="0" posX="2732.0244140625" posY="-1664.7092285156" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (6)" interior="0" posX="2729.9995117188" posY="-1664.6420898438" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (7)" interior="0" posX="2728.04296875" posY="-1664.6704101563" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (8)" interior="0" posX="2725.798828125" posY="-1664.7028808594" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (9)" interior="0" posX="2723.7026367188" posY="-1664.6372070313" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (10)" interior="0" posX="2721.4497070313" posY="-1664.8138427734" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
   <spawnpoint id="spawnpoint (11)" interior="0" posX="2741.6684570313" posY="-1664.3295898438" posZ="13.2421875" rotX="0" rotY="0" rotZ="0" />
</map>

I have already test it in debugging mode.

Edited by Guest
Link to comment

I'm creating a new gamemode. For now it is a test. But if it work i complete it. The spawnplayer function don't work... all work but it don't work.

The gamemode have the editor definitions and that works.

--RTFI GAMEMODE by Loren_ita rootElement = getRootElement () function startMap( startedMap )  mapRoot = getResourceRootElement( startedMap )  triggerEvent ( "PlayerSpawn", rootElement )end addEvent ( "PlayerSpawn", true ) function joinHandler( thePlayer  )  local SpawnElements = getElementsByType ( "spawnpoint", mapRoot )	for key, value in pairs(SpawnElements) do       x = getElementData( value, "posX" )       y = getElementData( value, "posY" )       z = getElementData( value, "posZ" )       r = getElementData( value, "rot" ) or 0     end    spawnPlayer ( thePlayer , x, y, z, r, math.random (0,288))end function respawndied()    setTimer( joinHandler, 1800, 1 )end function spawnJoin()    setTimer( joinHandler,1000, 1 )end addEventHandler ("PlayerSpawn", rootElement, joinHandler)addEventHandler ("onGamemodeMapStart", getRootElement(), startMap)addEventHandler ("onPlayerWasted", getRootElement(), respawndied )addEventHandler ("onPlayerJoin", getRootElement(), spawnJoin )

EDF:

							     

map:

                                                                                                    

I have already test it in debugging mode.

Edited by Guest
Link to comment

https://wiki.multitheftauto.com/wiki/Character_Skins

List of valid skin IDs.

And in case you are even lazier than clicking a link:

Non-working IDs

1-6 8 42 65 74 86 119 149 208 265-273

The best option around this is to use

repeat until spawnPlayer ( thePlayer , x, y, z, r, math.random (0,288)) end

Edit: Quick glance at your code reveals that IF it's getting the data from the map file correctly (I didn't look at that) your loop will overwrite x,y,z,r each time, then the values they will actually contain every single time it reaches spawnPlayer will be the ones for your final spawnpoint in the map file. Use:

local value = SpawnElements[math.random(#SpawnElements)]
local x = getElementData( value, "posX" )
local y = getElementData( value, "posY" )
local z = getElementData( value, "posZ" )
local r = getElementData( value, "rotZ" ) or 0
repeat until spawnPlayer ( thePlayer , x, y, z, r, math.random (0,288)) end

This will pick a random spawnpoint element rather than loop through all of them.

Edit2: getElementData( value, "rot" ) is returning nil. It doesn't exist, as your map file contains "rotX, rotY, rotZ" values.

Edit3: Your timers are not passing "thePlayer" to your joinHandler function.

Alter them:

setTimer( joinHandler, 1800, 1, source )

Edit4: This just won't work. (Line 7)

triggerEvent ( "PlayerSpawn", rootElement )

Again, it will not receive "thePlayer". You should use getElementsByType("player") and loop through them, triggering your event for each and making sure to pass on the player element.

Edited by Guest
Link to comment

https://wiki.multitheftauto.com/wiki/Character_Skins

List of valid skin IDs.

And in case you are even lazier than clicking a link:

Non-working IDs

1-6 8 42 65 74 86 119 149 208 265-273

The best option around this is to use

repeat until spawnPlayer ( thePlayer , x, y, z, r, math.random (0,288)) end

Edit: Quick glance at your code reveals that IF it's getting the data from the map file correctly (I didn't look at that) your loop will overwrite x,y,z,r each time, then the values they will actually contain every single time it reaches spawnPlayer will be the ones for your final spawnpoint in the map file. Use:

local value = SpawnElements[math.random(#SpawnElements)]
local x = getElementData( value, "posX" )
local y = getElementData( value, "posY" )
local z = getElementData( value, "posZ" )
local r = getElementData( value, "rotZ" ) or 0
repeat until spawnPlayer ( thePlayer , x, y, z, r, math.random (0,288)) end

This will pick a random spawnpoint element rather than loop through all of them.

Edit2: getElementData( value, "rot" ) is returning nil. It doesn't exist, as your map file contains "rotX, rotY, rotZ" values.

Edit3: Your timers are not passing "thePlayer" to your joinHandler function.

Alter them:

setTimer( joinHandler, 1800, 1, source )

Edit4: This just won't work. (Line 7)

triggerEvent ( "PlayerSpawn", rootElement )

Again, it will not receive "thePlayer". You should use getElementsByType("player") and loop through them, triggering your event for each and making sure to pass on the player element.

Edited by Guest
Link to comment

... i know that. When i start the gamemode it don't spawn me... and if i start the gamemode with the server and i enter in it the gamemode don't spawn me....

This is server.lua:

--RTKI GAMEMODE by Loren_ita
 
rootElement = getRootElement ()
 
function startMap( startedMap )
 mapRoot = getResourceRootElement( startedMap )
 triggerEvent ( "PlayerSpawn", rootElement )
end
 
addEvent ( "PlayerSpawn", true )
 
function joinHandler( thePlayer  )
 local SpawnElements = getElementsByType ( "spawnpoint", mapRoot )
for key, value in pairs(SpawnElements) do
     local value = SpawnElements[math.random(#SpawnElements)]
     local x = getElementData( value, "posX" )
     local y = getElementData( value, "posY" )
     local z = getElementData( value, "posZ" )
     local r = getElementData( value, "rotZ" ) or 0
     repeat until spawnPlayer ( thePlayer , x, y, z, r, math.random (0,288))
    end
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

Be patient and in the mean time, research.

Do you get the same warning about bad argument in spawnPlayer? If so, you may have to convert the coords you get with getElementData to number before you pass it to spawnPlayer. You usually get string when you try to take data from an element which was created by .map file.

local x = tonumber( getElementData( value, "posX" ) );

Link to comment
local SpawnElements = getElementsByType ( "spawnpoint", mapRoot )
for key, value in pairs(SpawnElements) do   --DELETE THIS LINE!!!
local value = SpawnElements[math.random(#SpawnElements)]
local x = tonumber( getElementData( value, "posX" ) )  --50p was correct in that these have to be converted to numbers, I missed that
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   --DELETE THIS LINE!!!

Do you have any notion of code execution AT ALL?

Look back to what I said earlier:

Edit: Quick glance at your code reveals that IF it's getting the data from the map file correctly (I didn't look at that) your loop will overwrite x,y,z,r each time, then the values they will actually contain every single time it reaches spawnPlayer will be the ones for your final spawnpoint in the map file.

I told you what to put in instead of looping through, and you totally ignored me and just pasted in my replacement, IN THE LOOP I TOLD YOU NOT TO USE.

You are currently spawning the same player over and over again for as many times as you have spawnpoints.

Remove the for...do ... end loop lines altogether. You do NOT need to parse every spawnpoint, just pick one of them, which the code I wrote for you did.

This will be the last time I help you in this matter, as clearly you just want someone to just fix your code for you. I help people correct their mistakes, not do their work for them.

Link to comment

Sorry, realy sorry. I did not understand what you said before. Sorry again... but i can't find a guide in italian of LUA basics.

Now the script is that:

--RTKI GAMEMODE by Loren_ita
rootElement = getRootElement ()
players = getElementsByType("player")
 
function startMap( startedMap )
   mapRoot = getResourceRootElement( startedMap )
   triggerEvent ( "PlayerSpawn", rootElement, players )
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 )

The debugscript sai this countless times:

WARNING: server.lua: Bad argument @ 'spawnPlayer' - line: 20

I don't understand what i'm doing wrong because i don't understand good LUA.

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