Jump to content

[Help]Getting My Panel To Spawn Drivable Car


kewizzle

Recommended Posts

okay so heres what i have done so far...

Server

function spawnCarrr() 
admin = getLocalPlayer() 
x, y, z = getElementPosition( admin ) 
createVehicle(411, x+3, y+3, z) 
end 
addEvent("spawnCarrr", true) 
addEventHandler("spawnCarrr", root, spawnCarrr) 

Client

function spawnCarr() 
triggerServerEvent("spawnCarrr", root) 
end 

it all works i just need a way to make getLocalPlayer work on server side it there another Event that can be used or what? Cause if i put the vehicle spawn script client side it works right but non drivable..

Link to comment

getLocalPlayer() is only client-side, it does nothing on your current code.

This is a working code. Read the notes I left below, so you learn why is this working:

Server

function spawnCarrr() 
local x, y, z = getElementPosition( client ) 
createVehicle(411, x+3, y+3, z) 
end 
addEvent("spawnCarrr", true) 
addEventHandler("spawnCarrr", root, spawnCarrr) 

Client

function spawnCarr() 
triggerServerEvent("spawnCarrr", root) 
end 

NOTES:

"client" is a player element parameter passed by any client-triggered event, read more at https://wiki.multitheftauto.com/wiki/TriggerServerEvent

"local x,y,z" is a setup so those 3 variables don't get in the way for other functions that use the same variable names. Read more at http://www.lua.org/pil/4.2.html

Edited by Guest
Link to comment

try

  
-- server 
function spawnCarrr() 
x, y, z = getElementPosition( source ) 
createVehicle(411, x+3, y+3, z) 
end 
addEvent("spawnCarrr", true) 
addEventHandler("spawnCarrr", root, spawnCarrr) 
  
--client 
function spawnCarr() 
triggerServerEvent("spawnCarrr", localPlayer) 
end 

Link to comment

or

-- server 
function spawnCarrr(p) 
x, y, z = getElementPosition( p ) 
createVehicle(411, x+3, y+3, z) 
end 
addEvent("spawnCarrr", true) 
addEventHandler("spawnCarrr", root, spawnCarrr) 
  
--client 
function spawnCarr() 
triggerServerEvent("spawnCarrr",root,localPlayer) 
end 

or

  
-- server 
function spawnCarrr(x,y,z) 
createVehicle(411, x+3, y+3, z) 
end 
addEvent("spawnCarrr", true) 
addEventHandler("spawnCarrr", root, spawnCarrr) 
  
--client 
function spawnCarr() 
local x, y, z = getElementPosition( localPlayer) 
triggerServerEvent("spawnCarrr",root,x,y,z) 
end 

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