Jump to content

addEventHandler problem with argument


John Smith

Recommended Posts

This should be changed to

addEventHandler("onPlayerJoin",source,spawnSumoPlayer) -- Line 9 
addEventHandler("onPlayerSpawn",source,spawnSumoPlayer) -- Line 35 

this

addEventHandler("onPlayerJoin",getRootElement(),spawnSumoPlayer) -- Line 9 
addEventHandler("onPlayerSpawn",getRootElement(),spawnSumoPlayer) -- Line 35 

Edited by Guest
Link to comment
addEventHandler("onPlayerJoin",source,spawnSumoPlayer) 

Change 'source' to 'root' and remove 'source' from function name, it's already defined by itself.

Also, this makes no sense:

spawnPoints = { [1]=true, [2]=true, } 
spawnPlayer(source,spawnPoints[math.random (1,2)]) 

You are giving spawnPlayer a boolean ( true ).

Link to comment

As solidsnake said, that doesn't make sense, try my code below :P

spawnPoints = { 
 -- { x, y, z } 
} 
  
function spawnSumoPlayer() 
   for i,v in ipairs (spawnPoints) do 
    spawnPlayer(source,v[1], v[2], v[3] ) 
end 
end 
addEventHandler("onPlayerJoin",getRootElement(),spawnSumoPlayer) 

Link to comment

thanks again solidsnake14,but i got another problem

here is my wrong part of code..again

spawnPoints = { 
[1] = { 2702.2, -3018.6, 99.9 }, 
[2] = { 2696.7, -3015.9, 99.9 } 
} 
  
function spawnSumoPlayer(source) 
   for i,v in ipairs (spawnPoints) do 
    spawnPlayer(source,spawnPoints[math.random v[1], v[2] ) 
end 
end 
addEventHandler("onPlayerJoin",getRootElement(),spawnSumoPlayer) 

i've never used math.random before so i didnt know exactly where to place it

it gives this error

[22:36:28] SCRIPT ERROR: [gamemodes]\[sumo]\sumo\load_map\spawn_s.lua:19: ']' expected near 'v'

[22:36:28] ERROR: Loading script failed: [gamemodes]\[sumo]\sumo\load_map\spawn_s.lua:19: ']' expect

ed near 'v'

Link to comment
spawnPoints = 
{ 
    [ 1 ] = { 2702.2, -3018.6, 99.9 }, 
    [ 2 ] = { 2696.7, -3015.9, 99.9 } 
} 
  
function spawnSumoPlayer ( ) 
    spawnPlayer ( source, unpack ( spawnPoints [ math.random ( #spawnPoints ) ] ) ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), spawnSumoPlayer ) 

Link to comment
function spawnSumoPlayer ( ) 
    spawnPlayer ( source, unpack ( spawnPoints [ math.random ( #spawnPoints ) ] ) ) 
    fadeCamera ( source, true ) 
    setCameraTarget ( source, source ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), spawnSumoPlayer ) 

Link to comment

okay thanks,

now it spawns me as a ped but why doesnt it spawn me into a random car?

car part of code

function changeVehicle (state) 
 if state == "Running" then 
  setTimer (function () 
    local players = getAlivePlayers () 
    for playerKey, playerValue in ipairs(players) do 
     setElementModel (getPedOccupiedVehicle(playerValue), vehicles[math.random(#vehicles)]) 
    end 
   end, 1000, 1) 
 end 
end 
addEvent("onRaceStateChanging", true) 
addEventHandler ("onRaceStateChanging", getRootElement (), changeVehicle) 
  
  
  
 function changePlayersVeh () 
 setElementModel (getPedOccupiedVehicle(source), vehicles[math.random(#vehicles)]) 
  
  
end 
addEvent("changeVeh", true) 
addEventHandler("changeVeh", getRootElement(), changePlayersVeh) 
addEventHandler("onPlayerSpawn",root,spawnSumoPlayer) 

probably an epic fail in there as i was just copying examples from wiki/other sites but it just needs to spawn me in random vehicle when player spawns

Link to comment

as im a noob,i've just copied few lines of code from some examples on wiki probably and didnt change race events at all cause i didn't know what to do with them,but i'm not using race gamemode at all, so i don't know how to spawn them inside a car

btw sry if im asking for too much i just wanna learn this since i cant learn on other way than asking in here

Link to comment
spawnPoints = 
{ 
    [ 1 ] = { 2702.2, -3018.6, 99.9 }, 
    [ 2 ] = { 2696.7, -3015.9, 99.9 } 
} 
vehicles = {602,545,496,517,401,410,518,600,527,436,589,580,419,439,533,549,526,491,474,445,604,507,585,587,466,492,546,551,516,467,426,547,405,409,550,566,540,421,529,581,509,481,462,521,463,510,522,461,448,468,586,485,552,431,438,437,574,420,525,408,416,433,427,490,528,407,544,523,470,598,596,597,599,601,428,499,609,498,524,532,578,486,406,573,455,588,403,514,423,414,443,515,531,456,459,422,482,605,530,418,572,582,413,440,543,583,478,554,536,575,534,567,535,576,412,402,542,603,475,568,424,504,457,483,508,571,500,444,556,557,471,495,539,429,541,415,480,562,565,323,492,502,503,411,559,561,560,506,451,558,555,477,579,400,404,489,505,479,442,458} 
  
function spawnSumoPlayer ( ) 
    local model = vehicles [ math.random ( #vehicles ) ] 
    local vehicle = createVehicle ( model, unpack ( spawnPoints [ math.random ( #spawnPoints ) ] ) ) 
    if spawnPlayer ( source, unpack ( spawnPoints [ math.random ( #spawnPoints ) ] ) ) then 
        fadeCamera ( source, true ) 
        setCameraTarget ( source, source ) 
        warpPedIntoVehicle ( source, vehicle ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), spawnSumoPlayer ) 

Link to comment

Thank you very very much!

just 1 more thing if you got time,

i've made a code to respawn player when he dies in his car

--1 part of big server side script(the one you saw before)

function respawnSumoPlayer ( ) 
    removeEventHandler("onPlayerJoin",true) 
    spawnPlayer ( source, unpack ( spawnPoints [ math.random ( #spawnPoints ) ] ) ) 
    fadeCamera ( source, true ) 
    setCameraTarget ( source, source ) 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), spawnSumoPlayer ) 

and

new made lua file

function onSumoPlayerVehicleExit(player) 
    if isPedInVehicle(player) then 
    killPed(player) 
else 
    outputDebugString("a player pressed enter/f key without being in a vehicle.") 
end 
end 
  
bindKey(player, "enter", "down", onSumoPlayerVehicleExit) 
bindKey(player, "f", "down", onSumoPlayerVehicleExit) 
  
addEventHandler("onVehicleStartExit",root,onSumoPlayerVehicleExit) 

idk how tho it spawns a ped into vehicle but how could i set a timer on this?

so that after death it respawns player after 5 seconds?

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