Gamesnert Posted July 3, 2008 Share Posted July 3, 2008 I've got myself into errors yet again... I'm busy on a GUI for creating, fixing... Name it! For vehicles. Now, I use the call function to make the GUI use my command I already made. /createvehicle. So I've been busy, and it doesn't work... Shame... Anyone knows what's wrong? My little testcode for the client's GUI: function createVehicleForPlayer(button) if button=="left" then local vehicleName=guiGridListGetItemText ( vehicleList, guiGridListGetSelectedItem(vehicleList), 1) if (vehicleName=="Buffalo") then local vehicleID=402 local player=getLocalPlayer() triggerServerEvent("playerVehicleRequest",player,vehicleID,player) outputChatBox("Vehicle " .. vehicleName .. " requested. It should appear soon...",0,255,0) else outputChatBox("" .. vehicleName .. "",255,0,0) end end end Server side script, activated by client: unction handleVehicleCreation(source, vehicleID, player) call(getResourceFromName("total-war-commands"), "createVehicleForPlayer", source, player, vehicleID) end addEvent("playerVehicleRequest", true) addEventHandler("playerVehicleRequest", getRootElement(), handleVehicleCreation) Server side final function called by the server side script activated by the client's GUI script: function createVehicleForPlayer(thePlayer, commandName, vehicleModel, requestedPlayer) if (requestedPlayer~=nil) then thePlayer=requestedPlayer end local x,y,z = getElementPosition(thePlayer) x = x + 5 z = z + 2 local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z) if (createdVehicle == false) then local vehicleID=getVehicleIDFromName(vehicleModel) local createdVehicle=createVehicle(tonumber(vehicleID),x,y,z) if(createdVehicle == false) then outputChatBox("Failed to create vehicle.",thePlayer,255,0,0) end end if(gastankExplodable) then setVehicleFuelTankExplodable(createdVehicle, true) else setVehicleFuelTankExplodable(createdVehicle, false) end end addCommandHandler("createvehicle", createVehicleForPlayer) Note that I messes around ALOT with all 3 codes, and may not make any sence now. And that of the gastank, well nevermind that. I have found out 1 thing: The script thinks that "thePlayer" is 402, the model ID. So there must be something wrong in the arguments... I just can't see what... Who can? Link to comment
50p Posted July 3, 2008 Share Posted July 3, 2008 1 advice: Try to avoid using "source" as a parameter especially in functions that are attached to events. It may lead (you and the script) to confusion. You triggerServerEvent with arguments: player, vehicleID, player Function in server-side script gets only 2 of them, vehicleID and player. source in handleVehicleCreation will be vehicleID and vehicleID will be player. Try to fix it by removing source from argument list in handleVehicleCreation. Read more about events and how they are triggered. You don't have to use player element in argument list if source will be the player element, unless you want to pass other player element. If you don't want to challenge yourself try this: http://pastebin.com/f3b49481d Link to comment
Gamesnert Posted July 3, 2008 Author Share Posted July 3, 2008 Look at that, works like a charm. ^^ So next time I must remember: -To let source out of arguments list. -Not put something in 2 times. -To not make such a mess of my script. Ok, I'll probably have another question in a week or less... But well, atleast these mistakes probably won't be in. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now