illestiraqi Posted March 31, 2013 Posted March 31, 2013 When I change rotation for configuration.slua, it doesent rotate the vehicle just stays north please help me fix it because I want change it maybe south or west or east not only north. Server: local vehicle = {} function isVehicleSpawned(vehicle) return getElementData(vehicle, "jobvehicle") end function doesPlayerHaveVehicleSpawned(player) if (isElement(vehicle[player])) then return true else return false end end function destroyVehicle(vehicle, player) if (isElement(vehicle[player])) then destroyElement(vehicle[player]) end end function createTheJobVehicles() for index, table in ipairs(vehicles) do marker = createMarker(table.x, table.y, table.z, "cylinder", 2, table.r, table.g, table.b) setElementData(marker, "vehiclemarker-role", table.Roles) setElementData(marker, "vehiclemarker-vehicles", table.vehicles) setElementData(marker, "vehiclemarker-rotation", table.rotation) vehicle[marker] = table.Roles local position = table.x..", "..table.y..", "..table.z..", "..", "..table.rotation local color = table.vehR..", "..table.vehG..", "..table.vehB..", " setElementData(marker, "vehiclemarker-position", position) setElementData(marker, "vehiclemarker-color", color) addEventHandler("onMarkerHit", marker, onPlayerVehicleMarkerHit) end end addEventHandler("onResourceStart", resourceRoot, createTheJobVehicles) function onPlayerVehicleMarkerHit(player) local role = getElementData(source, "vehiclemarker-role") local vehicles = getElementData(source, "vehiclemarker-vehicles") local rotation = getElementData(source, "vehiclemarker-rotation") if (getElementType(player) == "player") then if (getElementData(player, dataToFindPlayersJob) == role or role == "ALL") then if (isPedInVehicle(player)) then return end local position = getElementData(source, "vehiclemarker-position") local color = getElementData(source, "vehiclemarker-color") local posX, posY, posZ, rotation = unpack(split(position, ",")) local r, g, b = unpack(split(color, ",")) triggerClientEvent(player, "jobvehicles.showVehicleGUI", root, vehicles, rotation, posX, posY, posZ, rotation, r, g, b) end end end function onPlayerSpawnVehicle(vid, vx, vy, vz, rotation, r, g, b) if (isElement(vehicle[client])) then destroyElement(vehicle[client]) end vehicle[client] = createVehicle(vid, vx, vy, vz) setElementData(vehicle[client], "jobvehicle", true) warpPedIntoVehicle(client, vehicle[client]) setElementRotation(vehicle[client], 0, 0, rotation) outputDebugString(getPlayerName(client).. " has spawned a '"..getVehicleNameFromModel(vid)) outputServerLog(getPlayerName(client).. " has spawned a '"..getVehicleNameFromModel(vid).."'") if (r) then setVehicleColor(vehicle[client], r, g, b) end end addEvent("jobvehicles.onPlayerSpawnVehicle", true) addEventHandler("jobvehicles.onPlayerSpawnVehicle", root, onPlayerSpawnVehicle) function destroyPlayerVehicle() if (isElement(vehicle[source])) then destroyElement(vehicle[source]) end end addEventHandler("onPlayerWasted", root, destroyPlayerVehicle) addEventHandler("onPlayerLogout", root, destroyPlayerVehicle) addEventHandler("onPlayerQuit", root, destroyPlayerVehicle) function destroyMyOwnVehicle(player) if (isElement(vehicle[player])) then outputChatBox("You have succesfully destroyed your "..getVehicleNameFromModel(getElementModel(vehicle[player])).."!", player, 0, 255, 10) destroyElement(vehicle[player]) elseif (not isElement(vehicle[player])) then outputChatBox("You currently do not have a job vehicle spawned to destroy!", player, 250, 0, 0) end end addCommandHandler("destroyv", destroyMyOwnVehicle) function destroyVehicleOnExplode() if (getElementData(source, "jobvehicle")) then destroyElement(source) end end addEventHandler("onVehicleExplode", root, destroyVehicleOnExplode) function onAdminDestroyJobVehicle(admin, cmd, target) local accountname = getAccountName(getPlayerAccount(admin)) if (hasObjectPermissionTo("user."..accountname, "function.kickPlayer") and target) then local player = getPlayerFromName(target) if (isElement(vehicle[player]) and player) then outputChatBox("You have destroyed "..getPlayerName(player).."' s "..getVehicleNameFromModel(getElementModel(vehicle[player])).." (jobvehicle)", admin, 0, 255, 10) outputChatBox(getPlayerName(admin).." has destroyed your "..getVehicleNameFromModel(getElementModel(vehicle[player])).." (jobvehicle)", player, 255, 10, 0) destroyElement(vehicle[player]) elseif (not isElement(vehicle[player]) and player) then outputChatBox(getPlayerName(player).. " does not currently have any job vehicle spawned.", admin, 255, 10, 0) else outputChatBox("The player do not exist!", admin, 250, 0, 0) end end end addCommandHandler("dv", onAdminDestroyJobVehicle) Client: local screenWidth, screenHeight = guiGetScreenSize() local v_table = {} function createVehicleChooserGUI() if (isElement(wndVehicle)) then if (guiGetVisible(wndVehicle)) then return end end windowWidth, windowHeight = 321, 338 windowX, windowY = (screenWidth / 2) - (windowWidth / 2), (screenHeight / 2) - (windowHeight / 2) wndVehicle = guiCreateWindow(windowX, windowY, windowWidth, windowHeight, "Select Vehicle",false) guiSetAlpha(wndVehicle, 1) gridVehicle = guiCreateGridList(9,23,303,249,false,wndVehicle) vehicleColumn = guiGridListAddColumn(gridVehicle,"Vehicle",0.-- s8) --> vehicleSpawn = guiCreateButton(9,282,96,37,"Select",false,wndVehicle) vehicleClose = guiCreateButton(216,282,96,37,"Exit",false,wndVehicle) addEventHandler("onClientGUIClick", vehicleSpawn, onPlayerSelectVehicle) addEventHandler("onClientGUIClick", vehicleClose, onPlayerExitVehicleGUI) end function showVehicleGUI(vehicles, rotation, posX, posY, posZ, rotation, r, g, b) createVehicleChooserGUI() v_table[1] = posX v_table[2] = posY v_table[3] = posZ v_table[4] = rotation v_table[5] = r v_table[6] = g v_table[7] = b showCursor(true) guiGridListClear(gridVehicle) for index, vehicles in ipairs(vehicles) do vehicleRow = guiGridListAddRow(gridVehicle) guiGridListSetItemText(gridVehicle, vehicleRow, vehicleColumn, getVehicleNameFromModel(vehicles), false, true) end end addEvent("jobvehicles.showVehicleGUI", true) addEventHandler("jobvehicles.showVehicleGUI", root, showVehicleGUI) function onPlayerExitVehicleGUI(button, state) if (button ~= "left" or state ~= "up") then return end guiSetVisible(wndVehicle, false) showCursor(false) end function onPlayerSelectVehicle(button, state) if (button ~= "left" or state ~= "up") then return end if (guiGridListGetSelectedItem(gridVehicle) == -1) then return end local vrow = guiGridListGetSelectedItem(gridVehicle) local vname = guiGridListGetItemText(gridVehicle, vrow, vehicleColumn) local vid = getVehicleModelFromName(vname) guiSetVisible(wndVehicle, false) showCursor(false) triggerServerEvent("jobvehicles.onPlayerSpawnVehicle", root, vid, v_table[1], v_table[2], v_table[3], v_table[4], v_table[5], v_table[6], v_table[7]) end
TAPL Posted March 31, 2013 Posted March 31, 2013 Why do you use setElementRotation? You can use rotation arguments in function createVehicle.
illestiraqi Posted April 1, 2013 Author Posted April 1, 2013 I cant do it can I atleast have help I want this to be fixed only and this will help my server by 50% please.
tosfera Posted April 1, 2013 Posted April 1, 2013 Okee lets see; vehicle createVehicle ( int model, float x, float y, float z [, float rx, float ry, float rz, string numberplate, bool bDirection, int variant1, int variant2 ] ) The only things we are going to use are; int model = ID of the vehicle float x, y, z = the position of the car float rx, ry, rz = the rotation of the car You dont need anything else, so if you want the car to rotate to the north, do it like this; createVehicle(522, 0, 0, 5, 0, 0, 90); Thats all you need to do. Now its up to you to change your code into the new parameters from createVehicle
illestiraqi Posted April 1, 2013 Author Posted April 1, 2013 Okee lets see; vehicle createVehicle ( int model, float x, float y, float z [, float rx, float ry, float rz, string numberplate, bool bDirection, int variant1, int variant2 ] ) The only things we are going to use are; int model = ID of the vehicle float x, y, z = the position of the car float rx, ry, rz = the rotation of the car You dont need anything else, so if you want the car to rotate to the north, do it like this; createVehicle(522, 0, 0, 5, 0, 0, 90); Thats all you need to do. Now its up to you to change your code into the new parameters from createVehicle No no no. The cars already spawn north I want it to spawn south, east, west too not just north.
tosfera Posted April 1, 2013 Posted April 1, 2013 You want to spawn another car in another direction or change the position of the car to another direction? If so, then just use; setElementRotation
illestiraqi Posted April 1, 2013 Author Posted April 1, 2013 You want to spawn another car in another direction or change the position of the car to another direction? If so, then just use; setElementRotation I don't know how to add this thats why i posted the script here.
Castillo Posted April 1, 2013 Posted April 1, 2013 -- client side: local screenWidth, screenHeight = guiGetScreenSize() local marker function createVehicleChooserGUI() if (isElement(wndVehicle)) then if (guiGetVisible(wndVehicle)) then return end end windowWidth, windowHeight = 321, 338 windowX, windowY = (screenWidth / 2) - (windowWidth / 2), (screenHeight / 2) - (windowHeight / 2) wndVehicle = guiCreateWindow(windowX, windowY, windowWidth, windowHeight, "Select Vehicle",false) guiSetAlpha(wndVehicle, 1) gridVehicle = guiCreateGridList(9,23,303,249,false,wndVehicle) vehicleColumn = guiGridListAddColumn(gridVehicle,"Vehicle",0. vehicleSpawn = guiCreateButton(9,282,96,37,"Select",false,wndVehicle) vehicleClose = guiCreateButton(216,282,96,37,"Exit",false,wndVehicle) addEventHandler("onClientGUIClick", vehicleSpawn, onPlayerSelectVehicle) addEventHandler("onClientGUIClick", vehicleClose, onPlayerExitVehicleGUI) end function showVehicleGUI(vehicles, mkr) marker = mkr createVehicleChooserGUI() showCursor(true) guiGridListClear(gridVehicle) for index, vehicles in ipairs(vehicles) do vehicleRow = guiGridListAddRow(gridVehicle) guiGridListSetItemText(gridVehicle, vehicleRow, vehicleColumn, getVehicleNameFromModel(vehicles), false, true) end end addEvent("jobvehicles.showVehicleGUI", true) addEventHandler("jobvehicles.showVehicleGUI", root, showVehicleGUI) function onPlayerExitVehicleGUI(button, state) if (button ~= "left" or state ~= "up") then return end guiSetVisible(wndVehicle, false) showCursor(false) end function onPlayerSelectVehicle(button, state) if (button ~= "left" or state ~= "up") then return end if (guiGridListGetSelectedItem(gridVehicle) == -1) then return end local vrow = guiGridListGetSelectedItem(gridVehicle) local vname = guiGridListGetItemText(gridVehicle, vrow, vehicleColumn) local vid = getVehicleModelFromName(vname) guiSetVisible(wndVehicle, false) showCursor(false) triggerServerEvent("jobvehicles.onPlayerSpawnVehicle", localPlayer, vid, marker) end -- server side: local vehicle = {} function isVehicleSpawned(vehicle) return getElementData(vehicle, "jobvehicle") end function doesPlayerHaveVehicleSpawned(player) if (isElement(vehicle[player])) then return true else return false end end function destroyVehicle(vehicle, player) if (isElement(vehicle[player])) then destroyElement(vehicle[player]) end end function createTheJobVehicles() for index, table in ipairs(vehicles) do marker = createMarker(table.x, table.y, table.z, "cylinder", 2, table.r, table.g, table.b) setElementData(marker, "vehiclemarker-data", { table.Roles, table.vehicles, { table.x, table.y, table.z, table.rotation }, { table.vehR, table.vehG, table.vehB } }, false) addEventHandler("onMarkerHit", marker, onPlayerVehicleMarkerHit) end end addEventHandler("onResourceStart", resourceRoot, createTheJobVehicles) function onPlayerVehicleMarkerHit(player) local data = getElementData(source, "vehiclemarker-data") if (getElementType(player) == "player") then if (getElementData(player, dataToFindPlayersJob) == data [ 1 ] or data [ 1 ] == "ALL") then if (isPedInVehicle(player)) then return end triggerClientEvent(player, "jobvehicles.showVehicleGUI", root, data [ 2 ], source ) end end end function onPlayerSpawnVehicle(vid, marker) if (isElement(vehicle[client])) then destroyElement(vehicle[client]) end local data = getElementData ( marker, "vehiclemarker-data" ) local x, y, z, rot = unpack ( data [ 3 ] ) local r, g, b = unpack ( data [ 4 ] ) vehicle[client] = createVehicle(vid, x, y, z, 0, 0, rot) setElementData(vehicle[client], "jobvehicle", true) warpPedIntoVehicle(client, vehicle[client]) outputDebugString(getPlayerName(client).. " has spawned a '"..getVehicleNameFromModel(vid)) outputServerLog(getPlayerName(client).. " has spawned a '"..getVehicleNameFromModel(vid).."'") if (r and g and b) then setVehicleColor(vehicle[client], r, g, b) end end addEvent("jobvehicles.onPlayerSpawnVehicle", true) addEventHandler("jobvehicles.onPlayerSpawnVehicle", root, onPlayerSpawnVehicle) function destroyPlayerVehicle() if (isElement(vehicle[source])) then destroyElement(vehicle[source]) end end addEventHandler("onPlayerWasted", root, destroyPlayerVehicle) addEventHandler("onPlayerLogout", root, destroyPlayerVehicle) addEventHandler("onPlayerQuit", root, destroyPlayerVehicle) function destroyMyOwnVehicle(player) if (isElement(vehicle[player])) then outputChatBox("You have succesfully destroyed your "..getVehicleNameFromModel(getElementModel(vehicle[player])).."!", player, 0, 255, 10) destroyElement(vehicle[player]) elseif (not isElement(vehicle[player])) then outputChatBox("You currently do not have a job vehicle spawned to destroy!", player, 250, 0, 0) end end addCommandHandler("destroyv", destroyMyOwnVehicle) function destroyVehicleOnExplode() if (getElementData(source, "jobvehicle")) then destroyElement(source) end end addEventHandler("onVehicleExplode", root, destroyVehicleOnExplode) function onAdminDestroyJobVehicle(admin, cmd, target) local accountname = getAccountName(getPlayerAccount(admin)) if (hasObjectPermissionTo("user."..accountname, "function.kickPlayer") and target) then local player = getPlayerFromName(target) if (isElement(vehicle[player]) and player) then outputChatBox("You have destroyed "..getPlayerName(player).."' s "..getVehicleNameFromModel(getElementModel(vehicle[player])).." (jobvehicle)", admin, 0, 255, 10) outputChatBox(getPlayerName(admin).." has destroyed your "..getVehicleNameFromModel(getElementModel(vehicle[player])).." (jobvehicle)", player, 255, 10, 0) destroyElement(vehicle[player]) elseif (not isElement(vehicle[player]) and player) then outputChatBox(getPlayerName(player).. " does not currently have any job vehicle spawned.", admin, 255, 10, 0) else outputChatBox("The player do not exist!", admin, 250, 0, 0) end end end addCommandHandler("dv", onAdminDestroyJobVehicle) As you can see, I have changed how it works, I haven't tested it.
illestiraqi Posted April 1, 2013 Author Posted April 1, 2013 -- client side: local screenWidth, screenHeight = guiGetScreenSize() local marker function createVehicleChooserGUI() if (isElement(wndVehicle)) then if (guiGetVisible(wndVehicle)) then return end end windowWidth, windowHeight = 321, 338 windowX, windowY = (screenWidth / 2) - (windowWidth / 2), (screenHeight / 2) - (windowHeight / 2) wndVehicle = guiCreateWindow(windowX, windowY, windowWidth, windowHeight, "Select Vehicle",false) guiSetAlpha(wndVehicle, 1) gridVehicle = guiCreateGridList(9,23,303,249,false,wndVehicle) vehicleColumn = guiGridListAddColumn(gridVehicle,"Vehicle",0.-- s8) --> vehicleSpawn = guiCreateButton(9,282,96,37,"Select",false,wndVehicle) vehicleClose = guiCreateButton(216,282,96,37,"Exit",false,wndVehicle) addEventHandler("onClientGUIClick", vehicleSpawn, onPlayerSelectVehicle) addEventHandler("onClientGUIClick", vehicleClose, onPlayerExitVehicleGUI) end function showVehicleGUI(vehicles, mkr) marker = mkr createVehicleChooserGUI() showCursor(true) guiGridListClear(gridVehicle) for index, vehicles in ipairs(vehicles) do vehicleRow = guiGridListAddRow(gridVehicle) guiGridListSetItemText(gridVehicle, vehicleRow, vehicleColumn, getVehicleNameFromModel(vehicles), false, true) end end addEvent("jobvehicles.showVehicleGUI", true) addEventHandler("jobvehicles.showVehicleGUI", root, showVehicleGUI) function onPlayerExitVehicleGUI(button, state) if (button ~= "left" or state ~= "up") then return end guiSetVisible(wndVehicle, false) showCursor(false) end function onPlayerSelectVehicle(button, state) if (button ~= "left" or state ~= "up") then return end if (guiGridListGetSelectedItem(gridVehicle) == -1) then return end local vrow = guiGridListGetSelectedItem(gridVehicle) local vname = guiGridListGetItemText(gridVehicle, vrow, vehicleColumn) local vid = getVehicleModelFromName(vname) guiSetVisible(wndVehicle, false) showCursor(false) triggerServerEvent("jobvehicles.onPlayerSpawnVehicle", root, vid, marker) end -- server side: local vehicle = {} function isVehicleSpawned(vehicle) return getElementData(vehicle, "jobvehicle") end function doesPlayerHaveVehicleSpawned(player) if (isElement(vehicle[player])) then return true else return false end end function destroyVehicle(vehicle, player) if (isElement(vehicle[player])) then destroyElement(vehicle[player]) end end function createTheJobVehicles() for index, table in ipairs(vehicles) do marker = createMarker(table.x, table.y, table.z, "cylinder", 2, table.r, table.g, table.b) setElementData(marker, "vehiclemarker-data", { table.Roles, table.vehicles, { table.x, table.y, table.z, table.rotation }, { table.vehR, table.veG, table.vehB } }, false) addEventHandler("onMarkerHit", marker, onPlayerVehicleMarkerHit) end end addEventHandler("onResourceStart", resourceRoot, createTheJobVehicles) function onPlayerVehicleMarkerHit(player) local data = getElementData(source, "vehiclemarker-data") if (getElementType(player) == "player") then if (getElementData(player, dataToFindPlayersJob) == data [ 1 ] or data [ 1 ] == "ALL") then if (isPedInVehicle(player)) then return end triggerClientEvent(player, "jobvehicles.showVehicleGUI", root, data [ 2 ] ) end end end function onPlayerSpawnVehicle(vid, marker) if (isElement(vehicle[client])) then destroyElement(vehicle[client]) end local data = getElementData ( marker, "vehiclemarker-data" ) local x, y, z, rot = unpack ( data [ 3 ] ) local r, g, b = unpack ( data [ 4 ] ) vehicle[client] = createVehicle(vid, x, y, z, 0, 0, rot) setElementData(vehicle[client], "jobvehicle", true) warpPedIntoVehicle(client, vehicle[client]) outputDebugString(getPlayerName(client).. " has spawned a '"..getVehicleNameFromModel(vid)) outputServerLog(getPlayerName(client).. " has spawned a '"..getVehicleNameFromModel(vid).."'") if (r) then setVehicleColor(vehicle[client], r, g, b) end end addEvent("jobvehicles.onPlayerSpawnVehicle", true) addEventHandler("jobvehicles.onPlayerSpawnVehicle", root, onPlayerSpawnVehicle) function destroyPlayerVehicle() if (isElement(vehicle[source])) then destroyElement(vehicle[source]) end end addEventHandler("onPlayerWasted", root, destroyPlayerVehicle) addEventHandler("onPlayerLogout", root, destroyPlayerVehicle) addEventHandler("onPlayerQuit", root, destroyPlayerVehicle) function destroyMyOwnVehicle(player) if (isElement(vehicle[player])) then outputChatBox("You have succesfully destroyed your "..getVehicleNameFromModel(getElementModel(vehicle[player])).."!", player, 0, 255, 10) destroyElement(vehicle[player]) elseif (not isElement(vehicle[player])) then outputChatBox("You currently do not have a job vehicle spawned to destroy!", player, 250, 0, 0) end end addCommandHandler("destroyv", destroyMyOwnVehicle) function destroyVehicleOnExplode() if (getElementData(source, "jobvehicle")) then destroyElement(source) end end addEventHandler("onVehicleExplode", root, destroyVehicleOnExplode) function onAdminDestroyJobVehicle(admin, cmd, target) local accountname = getAccountName(getPlayerAccount(admin)) if (hasObjectPermissionTo("user."..accountname, "function.kickPlayer") and target) then local player = getPlayerFromName(target) if (isElement(vehicle[player]) and player) then outputChatBox("You have destroyed "..getPlayerName(player).."' s "..getVehicleNameFromModel(getElementModel(vehicle[player])).." (jobvehicle)", admin, 0, 255, 10) outputChatBox(getPlayerName(admin).." has destroyed your "..getVehicleNameFromModel(getElementModel(vehicle[player])).." (jobvehicle)", player, 255, 10, 0) destroyElement(vehicle[player]) elseif (not isElement(vehicle[player]) and player) then outputChatBox(getPlayerName(player).. " does not currently have any job vehicle spawned.", admin, 255, 10, 0) else outputChatBox("The player do not exist!", admin, 250, 0, 0) end end end addCommandHandler("dv", onAdminDestroyJobVehicle) As you can see, I have changed how it works, I haven't tested it. Somethings wrong because the gui wont open?
illestiraqi Posted April 1, 2013 Author Posted April 1, 2013 Check debugscript, look for any error. Whats the command I dont know how to debug?
illestiraqi Posted April 2, 2013 Author Posted April 2, 2013 The file name for the script is rpg-gangcar shows this: WARNING: Loading script failed: rpg-gangcar/veh.clua:13: unexpected symbol near "!"
illestiraqi Posted April 2, 2013 Author Posted April 2, 2013 When I try spawning a vehicle the gui comes up I select the vehicle and gives me this error: [2013-04-01 20:32:45] WARNING: rpg-gangcar\veh.slua:45: Bad argument @ 'getElementData' [Expected element at argument 1, got nil] [2013-04-01 20:32:45] ERROR: rpg-gangcar\veh.slua:46: attempt to index local 'data' (a boolean value)
illestiraqi Posted April 2, 2013 Author Posted April 2, 2013 Found my problem, copy it again. Omg ty so much i have another script that i need help with because no one helps me with it: viewtopic.php?f=91&t=56581
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