Jump to content

Small Question


Fabio(GNR)

Recommended Posts

i wont ask you why are you doing this through /run command.

put other type of quotes inside that quotes. can't you see it's breaking the string?

executeCommandHandler ( "run", playerSource, "setElementID(drv, 'drv')") 

Link to comment

No way to dont let this happen? why i do it this way is beceause im trying to control a driving ped ( doomedspacemarines vid on youtube ) and it worked but i want to experiment but typing all those command's gets annoying so i created the function that execute it after the timer i set in previous function ;)

EDIT: btw , the first function works, but the following give the bad argument :S

Link to comment
why you're executing commands when you can just execute the functions those commands execute?

i bet Doomed_Space_Marine made this step-by-step with commands just for educational purposes.

beceause i tried in a function but it gives alots of errors beceause it is being run before the serverside stuff is done

EDIT: this is what i got now:

-- server 
me=getPlayerFromNick("Fabio(GNR)") 
x,y,z = getElementPosition(me) 
car=createVehicle(411,x,y+3,z) 
drv=createPed(104,x,y+2,z) 
setElementID(drv,"drv") 
warpPedIntoVehicle(drv,car) 
setTimer(startclient, 3000, 1) 
  
 function startclient() 
 triggerClientEvent("start",me) 
 end 
  

Already gives me error: attempt to call global setElementID(a nil value) and if i put setElementID into startclient function, it gives bad argument at setTimer :S well:

-- client 
addEvent("start",true) 
addEventHandler("start",me, 
function () 
drv = getElementByID("drv") 
drvctrls = {accelerate="u",brake_reverse="j",vehicle_left="h",vehicle_right="k",steer_forward="x",steer_back="c",vehicle_look_left="e",vehicle_look_right="r"}  
setTimer(addevent, 2000, 1) 
end) 
  
function ctrldrv()  
for ctrl,key in pairs(drvctrls) do  
setPedControlState(drv,ctrl,getKeyState(key))  
end  
end 
  
function addevent() 
addEventHandler("onClientPreRender", getRootElement(), ctrldrv) 
end 
  

Link to comment

I don't know what about setElementID, but first you have to make sure that you are in the server when ped creation code is executed. In your script it's executed when the resource starts. Second, "start" event never gets triggered. Server tries to trigger it when the resource is starting and client-side script isn't running. Try putting the code into the command.

Link to comment
I don't know what about setElementID, but first you have to make sure that you are in the server when ped creation code is executed. In your script it's executed when the resource starts. Second, "start" event never gets triggered. Server tries to trigger it when the resource is starting and client-side script isn't running. Try putting the code into the command.

yes i was in the server but it wont even get further then setElementID beceause its an ERROR, thanks for reply but do you know a other way to pass the drv element? ( one of the ways in vid )

Link to comment
-- server 
addCommandHandler("letsroll",  
function(me) 
  local x,y,z = getElementPosition(me) 
  local car=createVehicle(411,x,y+3,z) 
  local drv=createPed(104,x,y+2,z) 
  setElementID(drv,"drv") 
  warpPedIntoVehicle(drv,car) 
  triggerClientEvent(me, "start", getRootElement()) 
end) 

-- client 
function ctrldrv() 
  for ctrl,key in pairs(drvctrls) do 
    setPedControlState(drv,ctrl,getKeyState(key)) 
  end 
end 
  
addEvent("start",true) 
addEventHandler("start", getRootElement(), 
function () 
  drv = getElementByID("drv") 
  drvctrls = {accelerate="u",brake_reverse="j",vehicle_left="h",vehicle_right="k",steer_forward="x",steer_back="c",vehicle_look_left="e",vehicle_look_right="r"} 
  addEventHandler("onClientPreRender", getRootElement(), ctrldrv) 
end) 

Link to comment
Your_Code ( preventing massive quote )

Thanks but, i get the same error as before, at setElementID

well that's strange, cause i had a server running and even have tested the code i posted above, it worked.

EDIT:are you sure your server-side code is really server-side?

Link to comment
Your_Code ( preventing massive quote )

Thanks but, i get the same error as before, at setElementID

well that's strange, cause i had a server running and even have tested the code i posted above, it worked.

Then it really strange, do you use nightly? me is nothing at your code, so i worked that in but then it gave setElementID before it gave attempt to perfom arithmetic on local "y"(a nil value)

EDIT; oh you edited and the answer is :shock::o:shock::o:shock::oops::oops::oops::oops: uh No.... i like copied a other meta but that was wrong hehe BUT Thanks alot!! Works great now thanks Aiboforcen and Doomed_Space_Marine Really appreciated ;)

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