Jump to content

kieran

Members
  • Posts

    367
  • Joined

  • Last visited

Everything posted by kieran

  1. So I have account data outputting to chat, as a test, but I want to add it to a table as I am trying to make a system where all accounts with the players current serial merge data into one account, the only problem is I want to insert it into a table like this: data = {accountName, dataName, dataValue} Here's my current code. local serial = getPlayerSerial( source ) local oldAccounts = getAccountsBySerial( serial ) if not oldAccounts == false then outputChatBox("You have an account and your data will now be transferred to the new one.", source, 50, 255, 200) dataSafe = {} --Empty table to save data for i=1,#oldAccounts do accounts = oldAccounts[i][1] local data = getAllAccountData( accounts ) -- get data if ( data ) then for k,v in pairs ( data ) do table.insert(dataSafe, oldAccounts, k, v) end end end for i=1,#dataSafe do local name, k, v = dataSafe[i][1],dataSafe[i][2],dataSafe[i][3]--x = key 1, y = key 2, z = key 3 outputChatBox(""..name..k..": "..v) -- print the key and value of each entry of data end end I came here asking as I am unsure about table.insert, I read a little online and it just confused me, hoping someone can help explain it. I've got the error: Attempt to index field '?' a userdata value <<< Line 7 If I do accounts = oldAccounts then I get error wrong number of arguments to 'insert' Thanks a lot for any help
  2. Can't edit post, but fixed it, I forgot that logIn returns false if you failed to log on, just needed an if to check if it was false and if it was, change the password for the account.
  3. Hello, I am making my first ever serial based login script, how it works is the player joins, triggers an event client side, if a file exists with the players password, it gets that password, otherwise it randomly generates letters and numbers and sets that as the account password and makes an xml file with the password... The problem is, I was curious to see if it generated secure passwords, good news, IT DID! But.... It meant deleting the old one and now me being a fool like I am, I have the wrong password, and long story short, I want to find a way to check if the password is refused... And a little info on setAccountPassword would be appreciated, gave it a try but it failed, here is my server code where I have the issue. function getOrSetPass() triggerClientEvent(source, "loginSerialPass", source)--Trigger event when player joins to fetch/create the password end addEventHandler("onPlayerJoin", root, getOrSetPass) function PlayerLogin(pass) --Carry the password to server side from a trigger event local username = getPlayerSerial( source ) --Get players serial local account = getAccount ( username, pass ) --Get the players account if ( account == false ) then --If the account does not exist addAccount(tostring(username), pass) --Add it account = getAccount ( username ) --Get the new account logIn(source, account, pass) --Log the player in else --HERE IS WHERE I WANT IT TO CHECK IF PASSWORD IS NOT CORRECT setAccountPassword(account, tostring(pass)) logIn(source, account, pass) end end addEvent("loginSerial",true) addEventHandler("loginSerial",getRootElement(),PlayerLogin) Thanks for any help.
  4. Ah right, thank you, I am still trying to get my head around all the small stuff, this helps
  5. Well one problem I see already is you have created a vehicle with the variable "vehicle" but in the script you are setting the data of "element vehicle", I'm sure there are other problems, but hopefully this is a start. The way it works is "vehicle" is the variable, so remove element as it is not defined, and maybe try to tidy up the function.... I don't see an end to your function either, maybe sort this too, and the brackets after function shouldn't have anything in them at the moment as your vehicle is created inside the function, not outside it, so you don't pass the data to your function, you are just passing empty variables.... Might be confusing, but every time you want to pass information, you put that in the brackets, mainly it's with event handlers, so for example... This server side function outputs a message to the player when they hit the marker, we carried the source (thePlayer) and the players dimension (matchingDimension) from the handler, as the handler returns these 2 values. marker = createMarker(0, 0, 0, "cylinder", 2, 255, 255, 0, 255) --x, y, z, type, size, r, g, b, a function markerHit( thePlayer, matchingDimension ) --thePlayer is the source element, we carried this from the handler. outputChatBox("It works!", thePlayer) --output a message to the player end addEventHandler("onMarkerHit", marker, markerHit) --The handler handles events, when player hits marker, the above function is triggered Your code looked a bit, and I'm sorry for this, but noobish, so I am trying to show you an example of a simple function, hope it helps... Also use this page: https://wiki.multitheftauto.com/wiki/SetElementData You will find all information you can put in element data, how it works, and the restrictions
  6. kieran

    Ghost Mode

    I ask for a lot of help on this forum, but that's because I make the scripts and find a load of bugs/errors, unfortunately, I am an idiot, so I post code I HAVE MADE, so that I can get help on how to fix certain problems I have struggled with for about a week or so. Go to YouTube and look up scripting tutorials. And please, make a new topic..... Press that "Start new topic" text and not the reply button, this isn't even your topic and you're asking for help on it... Go download scripts from community, mess around with them, start small and build up your skills, then when you actually know a little about coding, come back and ask for help THIS FORUM IS TO HELP PEOPLE WITH SCRIPTS, WE ARE NOT A CHARITY
  7. kieran

    Help me

    I guess you are doing getVehicleNameFromModel as well as a for loop to go through vehicle IDs and get there names, adding a row to a grid list, just add it to check the model, so if you see something like Name = getVehicleNameFromModel then add an if to change "Name" to "advanced hummer" It's hard to give you an answer when nobody has any code for your script, the point of giving a code snippet is so that we know how your script works and in this case, how you are adding the vehicle names.... If we knew that, it would of been solved 20 days ago If you downloaded resource from forums, then would be nice if you gave a link, that way we could add working code.
  8. It will actually be 20, when the player moves in col shape the gate rotates out and stops at 20 degrees, It's all done to an exact position, and the problem was my checking I was setting a 1.5 second timer to set my boolean's to true/false, so this means that a player could run into the col shape before the timer is complete, if you test the script it works fine, just needed tweaking, and as pa3ck said, I should of added a moving boolean and set it as soon as the gate starts moving... The reason I check exact rotation is because moveObject sets an elements position, with the starting rotation being it's current rotation, so this was the easiest way I could think of... But you make a great point, I must calculate it's current rotation and close it when the player leaves. Anyway thanks to both of you for help, sorted it and working well.
  9. I am currently trying to replace gates at KACC, I have a script that removes the gates, and creates new ones in their place, then when a player hits a col shape, gates open, the only problem is, I want to check if the gates are fully opened (at a certain rotation since moveObject adds/subtracts from current rotation) and only if they are, move them back, never really done rotations with moveObject, so this is a pretty hard thing to start on... Here is server side code. --Replace gates in KACC and add Col shape to open/close them removeWorldModel (985 , 7.3802581, 2497.2419, 2774.2747, 10.7167) removeWorldModel (986, 7.4280729, 2497.2119, 2768.4243, 11.38819) RGate = createObject (986, 2497.3999, 2769.0991, 11.53, 0, 0, 90) LGate = createObject (985, 2497.3999, 2777.0701, 11.53, 0, 0, 90) ColGate = createColCuboid (2487.15, 2765.28, 10, 20, 15.75, 5) isGateOpen = false --By default this is false local OpenTimer --In case I need to use these later to cancel timer local CloseTimer function KACC_Open ( thePlayer, matchingDimension ) --Open gate if getElementType ( thePlayer ) == "player" then if isTimer(OpenTimer) then --Checking for timer outputChatBox("Timer Found",thePlayer) end if isGateOpen == false then --If it's false x,y,z = getElementRotation(LGate) --Below if is how I tried fixing it, didn't work if not z == 20 then return end moveObject(RGate, 2000, 2493.3999, 2766.7, 11.53, 0, 0, 70) --Move the gate and add 70 to z rotation moveObject(LGate, 2000, 2493.3999, 2779.6, 11.53, 0, 0, -70) --Move the gate and subtract 70 from z rotation OpenTimer = setTimer(function() isGateOpen = true end,2000,1) --Set timer to put boolean to true end end end addEventHandler ( "onColShapeHit", ColGate, KACC_Open ) function KACC_Close ( thePlayer, matchingDimension ) --Close gate if getElementType ( thePlayer ) == "player" then if isGateOpen == true then --If it's true x,y,z = getElementRotation(LGate) --Below if is how I tried fixing it, didn't work if not z == 90 then return end moveObject (RGate, 2000, 2497.3999, 2769.0991, 11.53, 0, 0, -70) --Move the gate and subtract 70 from z rotation moveObject (LGate, 2000, 2497.3999, 2777.0701, 11.53, 0, 0, 70) --Move the gate and add 70 to z rotation CloseTimer = setTimer(function() isGateOpen = false end,2000,1) --Set a timer to put the boolean to false end end end addEventHandler ( "onColShapeLeave", ColGate, KACC_Close ) I know where I went wrong, the 2 second timer isn't enough to set it true as player can run in and out in that time, but how would I fix it? Because if I set it to true right away it moves too much the other way when I leave the col shape... Thanks for any suggestions/fixes
  10. Thanks, works great, but there's a slight problem with how I'm doing this (this is the last thing that needs fixed ) If you look at line 46 you'll see I set marker_data to be source, as it was originally spawning when you hit the marker and I'm remodeling it for GUI spawning, the reason I use marker_data is because it got the marker I was currently in, do you know of any other ways to get the marker other than using onMarkerHit handler and getting table index? local TruckerTeam = createTeam("Trucker", 20, 100, 150) TruckerMarker = {--marker [x,y,z] truck spawn point: [x,y,z,rotationx,rotationy,rotationz], [location] {2179.841796875, -2263.6940917969, 13.8, 2167.4401855469, -2273.9362792969, 14 ,-0, 0, 220, "Ocean Docks"}, {-1737.9622802734, 20.285757064819, 2.7, -1710, 10, 4, 0, 0, 315, "Easter Basin"}, {1643, 2354, 10, 1634, 2365, 11, -0, 0, 90, "Redsands West"} }--Above table is for the job markers, player walks into one, they become trucker and a truck is spawned. local markerStore = {} --Stores markers function TruckerStart ( hitElement, matchingDimension ) if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if not (isGuestAccount (getPlayerAccount (hitElement))) then local account = getPlayerAccount (hitElement) if (account) then local PlayerShipments = getAccountData( account, "Trucker.pres" ) if (PlayerShipments) then setElementData (hitElement, "Trucker.pres", PlayerShipments) else setElementData (hitElement, "Trucker.pres", 0) end triggerClientEvent ( hitElement, "spawnTruck", hitElement) end end end end addEvent("spawnTruckYes", true) addEventHandler("spawnTruckYes", root, function (hitElement) if isElement(hitElement) and getElementType(hitElement) == "player" then if ( TruckerTeam ) then if isPedOnGround ( hitElement ) then local playerTeam = getPlayerTeam ( hitElement ) if not ( playerTeam == TruckerTeam) then setPlayerTeam(hitElement, TruckerTeam) end local spawnedTruck = getElementData( hitElement, "Trucker.truck" ) --Check if they have spawned a truck if ( spawnedTruck ~= false ) then destroyElement(spawnedTruck) --If they have, destroy the truck spawnedTruck = nil setElementData(hitElement, "Trucker.truck", false) --Set there data to false else triggerClientEvent ( hitElement, "shipmentMarker", hitElement) local x, y, z, rx, ry, rz, name local marker_data = markerStore[source] --Getting the marker data if marker_data then outputDebugString("Marker data: "..marker_data) x,y,z,rx,ry,rz,name = marker_data[4],marker_data[5],marker_data[6],marker_data[7],marker_data[8],marker_data[9],marker_data[10] local Truck = createVehicle (515, x, y, z+1, rx, ry, rz) setElementData(hitElement, "Trucker.truck", Truck) warpPedIntoVehicle (hitElement, Truck) end end else outputChatBox("You must be on foot!", hitElement, 255, 0, 0) end end end end ) function createMarkers() for i=1,#TruckerMarker do local x,y,z = TruckerMarker[i][1],TruckerMarker[i][2],TruckerMarker[i][3]--x = key 1, y = key 2, z = key 3 local marker = createMarker( x,y,z,"cylinder", 1, 0, 200, 55, 255 ) markerStore[marker] = TruckerMarker[i] TruckerJobBlip = createBlipAttachedTo ( marker, 42, 2, 0, 0, 0, 0, 0, 500 ) addEventHandler("onMarkerHit", marker, TruckerStart) end end createMarkers() Can't thank you guys enough for the help.
  11. Both good points, but this was example code I typed quickly to show how I was trying to pass the PLAYER as an argument to server side, I will put actual code below, just made example because it's easier to read... In the script the marker is server side, as well as the vehicle spawning, change teams, and checks for element data. Server side is just GUI, sorry for the confusion with the bad example. Client Only need first 2 functions, third just shows you what I want to do if they click no. function spawnTheTruck() local screenW, screenH = guiGetScreenSize() window = guiCreateWindow((screenW - 312) / 2, (screenH - 104) / 2, 312, 104, "Spawn a truck or use your own?", false) guiWindowSetSizable(window, false) showCursor(true) label1 = guiCreateLabel(56, 27, 201, 17, "Yes - Spawn a truck.", false, window) label2 = guiCreateLabel(56, 40, 201, 17, "No - I brought my own.", false, window) guiLabelSetHorizontalAlign ( label1, "center") guiLabelSetHorizontalAlign ( label2, "center") Yes_btn = guiCreateButton(56, 64, 89, 30, "Yes", false, window) No_btn = guiCreateButton(168, 65, 89, 29, "No", false, window) addEventHandler("onClientGUIClick", Yes_btn, spawnYes) addEventHandler("onClientGUIClick", No_btn, spawnNo) end addEvent("spawnTruck", true) addEventHandler("spawnTruck", getRootElement(), spawnTheTruck) function spawnYes(button, state, hitElement) if source == Yes_btn and button == "left" and state == "up" then triggerServerEvent("spawnTruckYes", localPlayer, hitElement) destroyElement(window) showCursor(false) end end function spawnNo(button, state) if source == No_btn and button == "left" and state == "up" then --triggerServerEvent("spawnTruckNo", localPlayer, this) destroyElement(window) showCursor(false) end end Server Only need first 3 functions, last one is just there to show how markers are made. local markerStore = {} --Stores markers function TruckerStart ( hitElement, matchingDimension ) if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if not (isGuestAccount (getPlayerAccount (hitElement))) then local account = getPlayerAccount (hitElement) if (account) then local PlayerShipments = getAccountData( account, "Trucker.pres" ) if (PlayerShipments) then setElementData (hitElement, "Trucker.pres", PlayerShipments) else setElementData (hitElement, "Trucker.pres", 0) end triggerClientEvent ( hitElement, "spawnTruck", hitElement) end end end end function spawnNo(hitElement) --If player choses no in client side GUI, then they won't get a truck if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if ( TruckerTeam ) then if isPedOnGround ( hitElement ) then local playerTeam = getPlayerTeam ( hitElement ) if not ( playerTeam == TruckerTeam) then setPlayerTeam(hitElement, TruckerTeam) end --[[triggerClientEvent ( hitElement, "destroyIron", hitElement)<<Custom handler for iron miner script]] triggerClientEvent ( hitElement, "shipmentMarker", hitElement) else outputChatBox("You must be on foot!", hitElement, 255, 0, 0) end end end end addEvent("spawnTruckNo", true) addEventHandler("spawnTruckNo", getRootElement(), spawnNo) function spawnYes(hitElement)--If player choses yes in client side GUI, then they will get a truck if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if ( TruckerTeam ) then if isPedOnGround ( hitElement ) then local playerTeam = getPlayerTeam ( hitElement ) if not ( playerTeam == TruckerTeam) then setPlayerTeam(hitElement, TruckerTeam) end local spawnedTruck = getElementData( hitElement, "Trucker.truck" ) --Check if player has spawned a truck if ( spawnedTruck ~= false ) then destroyElement(spawnedTruck) --If they have, destroy the truck spawnedTruck = nil setElementData(hitElement, "Trucker.truck", false) --And set there data to false else triggerClientEvent ( hitElement, "destroyIron", hitElement) triggerClientEvent ( hitElement, "shipmentMarker", hitElement) local x, y, z, rx, ry, rz, name local marker_data = markerStore[source] if marker_data then x,y,z,rx,ry,rz,name = marker_data[4],marker_data[5],marker_data[6],marker_data[7],marker_data[8],marker_data[9],marker_data[10] local Truck = createVehicle (515, x, y, z+1, rx, ry, rz) setElementData(hitElement, "Trucker.truck", Truck) warpPedIntoVehicle (hitElement, Truck) end end else outputChatBox("You must be on foot!", hitElement, 255, 0, 0) end end end end addEvent("spawnTruckYes", true) addEventHandler("spawnTruckYes", getRootElement(), spawnYes) function createMarkers() for i=1,#TruckerMarker do local x,y,z = TruckerMarker[i][1],TruckerMarker[i][2],TruckerMarker[i][3] local marker = createMarker( x,y,z,"cylinder", 1, 0, 200, 55, 255 ) markerStore[marker] = TruckerMarker[i] TruckerJobBlip = createBlipAttachedTo ( marker, 42, 2, 0, 0, 0, 0, 0, 500 ) addEventHandler("onMarkerHit", marker, TruckerStart) end end createMarkers() Hope this helps you understand what I'm trying to accomplish...
  12. @<~KaMiKaZe~> what do you mean send the buttons? Do you mean passing localPlayer on the handler for buttons? Because that doesn't work, handlers can't take arguments like triggerEvent
  13. I have tried this, nothing happens, when I look at triggerServerEvent it's event, element, [arguments...] So my best guess is for hitElement (on custom event) to get the player from client side when they click a button, I need to pass localPlayer (which I have tried as well as "getLocalPlayer()" and "client") to the server as an argument, not just as an element... So it'd be this: triggerServerEvent("spawnTruck", localPlayer, localPlayer) Which doesn't work...
  14. I have a client side GUI with 2 buttons, if the player clicks yes, the local player should be carried to the server side script as "hitElement" I am doing this because "source" does nothing, and if I use getLocalPlayer() as an argument for the triggerEvent it returns an error saying it got a userdata value. -->[[Client]]<-- local marker = createMarker( 0,0,0,"cylinder", 2, 0, 200, 55, 255 ) --Marker function GUIwindow() local screenW, screenH = guiGetScreenSize() window = guiCreateWindow((screenW - 312) / 2, (screenH - 104) / 2, 312, 104, "", false)--GUI guiWindowSetSizable(window, false) showCursor(true) label = guiCreateLabel(56, 30, 201, 17, "Do you want to spawn a truck?", false, window) yes_btn = guiCreateButton(56, 64, 89, 30, "Yes", false, window) --Button no_btn = guiCreateButton(168, 65, 89, 29, "No", false, window) addEventHandler("onClientGUIClick", yes_btn, triggerEvent) --Handler end addEventHandler("onMarkerHit", marker, GUIwindow) function triggerEvent(button, state) if source == yes_btn and button == "left" and state == "up" then triggerServerEvent("spawnTruck", localPlayer, getLocalPlayer()) --Trying to carry local player as hitElement to server destroyElement(window) showCursor(false) end end -->[[Server]]<-- function spawnTheTruck(hitElement)--If player choses yes in client side GUI, then they will get a truck if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if isPedOnGround ( hitElement ) then --If so, check if player is on foot local Truck = createVehicle (515, 0, 5, 5, 0, 0, 0) warpPedIntoVehicle (hitElement, Truck) end end end addEvent("spawnTruck", true) addEventHandler("spawnTruck", getRootElement(), spawnTheTruck) --Server side event Info of why the triggerEvent isn't working would be nice, thanks for help.
  15. Made a trucker script, but I want to set the players data when there truck/trailer explodes, so I tried a for loop and the idea was to get all players element data and set it to false if the source was there vehicle... function ExitVehicle(thePlayer) --This function works fine, is just here to give you an idea of what I'm trying ti achieve if getPlayerTeam(thePlayer) == (TruckerTeam) then local spawnedTruck = getElementData( thePlayer, "Trucker.truck" ) local theTrailer = getElementData( thePlayer, "Trucker.trailer" ) --Name changed from spawnedTrailer to prevent conflict if (spawnedTruck) then outputChatBox("You have 20 seconds to get back to your truck!", thePlayer) TruckTimer = setTimer(function() if ( spawnedTruck ~= false ) then --(~= is not equal) destroyElement(spawnedTruck) setElementData(thePlayer, "Trucker.truck", false) end if (theTrailer) ~= false then destroyElement(theTrailer) setElementData(thePlayer, "Trucker.trailer", false) end triggerClientEvent(thePlayer, "destroyMarker", thePlayer) triggerClientEvent(thePlayer, "shipmentMarker", thePlayer) end,20000,1) end if not (spawnedTruck) and (theTrailer) then outputChatBox("You have 20 seconds to get back to your truck!", thePlayer) TrailerTimer = setTimer(function() destroyElement(theTrailer) triggerClientEvent(thePlayer, "destroyMarker", thePlayer) setElementData(thePlayer, "Trucker.trailer", false) triggerClientEvent(thePlayer, "shipmentMarker", thePlayer) end,20000,1) end end end addEventHandler("onVehicleExit",getRootElement(),ExitVehicle) --When vehicles explode the players data will be removed function explodingTruck() for _,player in ipairs(getElementsByType("player")) do --LOOP through all players local spawnedTruck = getElementData( player, "Trucker.truck" ) --The data is the players vehicle, set when the player spawned it. local theTrailer = getElementData( player, "Trucker.trailer" ) --^^^ if source == spawnedTruck then --If the source was the players vehicle setElementData(player, "Trucker.truck", false) --The idea is to set there data to false so they can spawn another one if the server has automatic respawn/deletion for vehicles. end if source == theTrailer then setElementData(player, "Trucker.trailer", false) triggerClientEvent(player, "destroyMarker", player) --Obviously I want to destroy the players mission blip and marker if they have a trailer, but it fails to get the player. end end end addEventHandler("onVehicleExplode",getRootElement(),explodingTruck) Full resource can be found here if you need more code: https://community.multitheftauto.com/?p=resources&s=details&id=15161 debugscript 3 When the timer to check for data (check if the player has a vehicle spawned) is done, the below shows, clearly showing me that it failed to set players data to false. [2018-01-14 22:35:14] WARNING: RP-Trucker\Trucker_s.lua:188: Bad argument @ 'destroyElement' [Expected element at argument 1] [2018-01-14 22:35:14] WARNING: RP-Trucker\Trucker_s.lua:192: Bad argument @ 'destroyElement' [Expected element at argument 1] Any help with it would be nice, I want the community to have a perfect RP resource, plus it'll help me learn to make new ones ^.^ Thanks in advance!
  16. Here's an idea (someone helped me understand this as I had similar issues) try setting the players element data to the vehicle, then when they die, get the data, here's untested code, if it doesn't work do a debugscript 3 and tell me the errors. function spawnVeh (thePlayer) --This function adds a command that spawns a car and sets players data, we will remove the car later local x, y, z = getElementPosition (thePlayer) --Get players position local rotX, rotY, rotZ = getElementRotation (thePlayer) --Get there rotation veh = createVehicle (468, x, y, z+5, rotX, rotY, rotZ) --Create the vehicle at the players position +5 height warpPedIntoVehicle (thePlayer, veh) --Warp the player into the vehicle setElementData(thePlayer, "freecar", veh) --Set the players data to the car end addCommandHandler("sanchez", spawnVeh) --When command is passed we create a sanchez above and set players data function removeVehicle () local theVeh = getElementData( source, "freecar" ) --First we get the players element data if ( theVeh ~= false ) then --If the data exists, it means the vehicle exists (unless you have done above command and the car gets destroyed) destroyElement(theVeh) --Since we got the element with getElementData above we can now destroy it setElementData(source, "freecar", false) --We now set the players data to false. end end addEventHandler("onPedWasted", getRootElement(), removeVehicle) --When player dies we trigger our function to check there data Hopefully this works!
  17. Here's a link to the MTA channel on YouTube, it explains how you make, export, and load a custom object into your server, it's also pretty funny Custom Map Models Tutorial Time that the script is made for importing the custom object
  18. I have made a trucker script, but have a few issues destroying markers, the idea is, I trigger a client side event to make multiple markers and add handlers to them, so when I hit the markers a GUI pops up, when I click accept, a marker and blip is created client side and a server side event is triggered to make a trailer, but I want to add all the markers to a table and destroy them when I click accept, but only one is destroyed, there are no errors on debug script 3, code below... --x, y, z, location, cash Locations = { [1] = {-1351.5205078125, -503.66796875, 14.171875, "SF Airport"}, [2] = {2838.658203125, 999.6708984375, 10.75, "East LV"}, [3] = {2262.89453125, 2792.927734375, 10.8203125, "Near KACC"}, [4] = {2763.138671875, -2421.6845703125, 13.486039161682, "Test"}, [5] = {-576.53063964844, -550.34674072266, 25.529611587524, "Fallen Tree"} } Markers = { [1] = {2762.677734375, -2431.4296875, 12.5}, [2] = {2747.6467285156, -2410.5747070313, 13.45193195343} } local GoodsMarker --Make a global variable local markerVault = {} -- local Name local marker local blip local cash window = {} function showGUI() local screenW, screenH = guiGetScreenSize() window = guiCreateWindow((screenW - 498) / 2, (screenH - 266) / 2, 498, 266, "Shipments", false) guiWindowSetSizable(window, false) gridlist = guiCreateGridList(9, 27, 479, 194, false, window) colLocation = guiGridListAddColumn(gridlist, "Location", 0.33) colDistance = guiGridListAddColumn(gridlist, "Distance", 0.33) colCash = guiGridListAddColumn(gridlist, "Cash", 0.33) for i=1,#Locations do --Here is the information for gridlist local x,y,z,text = Locations[i][1],Locations[i][2],Locations[i][3],Locations[i][4] --x,y,z,name of the location local px,py,pz = getElementPosition(localPlayer) --Get players position local distance = getDistanceBetweenPoints3D(px,py,pz,x,y,z) --get the distance between player and each point cash = math.floor(distance*3) --distance x 3 is the cash the player will get, rounded it so it's an integer not a float local row = guiGridListAddRow ( gridlist,text, math.floor(distance), cash ) --add a row for each table index... rounded distance so it doesn't look horrible end btn_acc = guiCreateButton(72, 231, 140, 25, "Accept", false, window) --accept button guiSetFont(btn_acc, "sa-header") btn_exit = guiCreateButton(284, 231, 140, 25, "Exit", false, window) --exit button guiSetFont(btn_exit, "sa-header") showCursor(true) local playerVehicle = getPedOccupiedVehicle ( localPlayer ) --Freeze player if (playerVehicle) then setElementFrozen ( playerVehicle, true ) end addEventHandler("onClientGUIClick", btn_acc, Accept) addEventHandler("onClientGUIClick", btn_exit, Exit) end addEvent("TruckerStart", true) --triggered server side when a player hits a marker addEventHandler("TruckerStart", getRootElement(), showGUI) function Accept(button, state) if source == btn_acc and button == "left" and state == "up" then Name = guiGridListGetItemText(gridlist,guiGridListGetSelectedItem(gridlist),1) --Get the name (text) from gridlist (Location[4]) of selected row local x, y, z for i=1,#Locations do --For all locations I check the selected name against the rows in the table if Name == Locations[i][4] then x, y, z = Locations[i][1], Locations[i][2], Locations[i][3] end end if isElement (marker) then --if the player has already made a marker I remove handler and destroy the marker removeEventHandler("onClientMarkerHit", marker, reward) destroyElement(marker) destroyElement(blip) end marker = createMarker( x,y,z-1,"cylinder", 3, 0, 100, 0, 100 ) --I create the marker and blip and add the handler blip = createBlipAttachedTo(marker, 51 ) --Type, Size, R, G, B addEventHandler("onClientMarkerHit", marker, reward) removeEventHandler("onClientGUIClick", btn_acc, Accept) --I remove the handler from this function destroyElement(window) --I destroy the window, hide the cursor and trigger an event to make a trailer showCursor(false) triggerServerEvent("createTrailer", localPlayer) if isElement (GoodsMarker) then --AND HERE IS WHERE I HAVE AN ISSUE, I want to destroy the markers I made on the function at the bottom local marker_data = markerVault[source] if marker_data then for i=1, #marker_data do destroyElement(i) end end end local playerVehicle = getPedOccupiedVehicle ( localPlayer ) --Unfreeze player if (playerVehicle) then -- set the new freeze status setElementFrozen ( playerVehicle, false ) end end end function Exit(button, state) --Exit button destroys window and creates marker if source == btn_exit and button == "left" and state == "up" then removeEventHandler("onClientGUIClick", btn_acc, Accept) removeEventHandler("onClientGUIClick", btn_exit, Exit) destroyElement(window) showCursor(false) triggerEvent("shipmentMarker", localPlayer) local playerVehicle = getPedOccupiedVehicle ( localPlayer ) if (playerVehicle) then setElementFrozen ( playerVehicle, false ) end end end function reward() --Give the player reward and destroy marker for i=1,#Locations do if Name == Locations[i][4] then destroyElement(marker) destroyElement(blip) triggerServerEvent("truckerReward", localPlayer, cash) triggerEvent ("TruckerStart", localPlayer) end end end function makeGoodsMarker() --For each line in table, I make a marker for i=1,#Markers do local x,y,z = Markers[i][1],Markers[i][2],Markers[i][3]--x = key 1, y = key 2, z = key 3 GoodsMarker = createMarker( x,y,z,"cylinder", 5, 0, 200, 55, 255 ) markerVault[i] = GoodsMarker TruckerJobBlip = createBlipAttachedTo ( GoodsMarker, 56 ) addEventHandler("onClientMarkerHit", GoodsMarker, trailerSpawn) end end addEvent("shipmentMarker", true) --I add a custom event as I want to trigger it again when the player clicks exit on GUI addEventHandler("shipmentMarker", getRootElement(), makeGoodsMarker) Markers made on line 128, meant to be destroyed on line 82. Thanks for any help, been struggling with this for a while.
  19. You made a marker, but you forgot to put the marker inside the interior When you create markers, they are the same as any other element, interior 0, dimension 0, until you set there interior/dimension, try this. local yMarker = createMarker (2104.7353515625, -1806.4340820313, 12.5, "cylinder", 0.5, 255, 255, 0) function yMarker (hitPlayer, matchingDiemension) if matchingDiemension and hitPlayer == localPlayer then outputChatBox ("Has entered the shop") setElementInterior ( localPlayer, 5, 372.40167236328, -132.85858154297, 1001.4921875) end end addEventHandler ("onClientMarkerHit", root, yMarker) local rMarker = createMarker (372.40167236328, -132.85858154297, 1001.4921875, "cylinder", 0.5, 255, 255, 0) setElementInterior ( rMarker, 5) Also it is important to note, if you set your players position/interior at the marker where you exit, the player will be moving between markers forever unable to move away.
  20. @TRtam I thought it was something like this, but first ever grid list script that's working with tables haha, worked perfect thanks!
  21. I am trying to make a grid list GUI, the idea is to add the contents of the table to the grid list, and then check the first column against the table data, if the name is equal to the row index on table, then get the xyz and create a marker. Made the GUI, but making the marker is what I'm struggling with... --x, y, z, location, cash Locations = { [1] = {-1351.5205078125, -503.66796875, 14.171875, "SF Airport", 15000}, [2] = {2838.658203125, 999.6708984375, 10.75, "East LV", 12000}, [3] = {2262.89453125, 2792.927734375, 10.8203125, "Near KACC", 12500} } window = {} local Name local marker function showGUI() local screenW, screenH = guiGetScreenSize() window = guiCreateWindow((screenW - 498) / 2, (screenH - 266) / 2, 498, 266, "Shipments", false) guiWindowSetSizable(window, false) gridlist = guiCreateGridList(9, 27, 479, 194, false, window) colLocation = guiGridListAddColumn(gridlist, "Location", 0.33) colDistance = guiGridListAddColumn(gridlist, "Distance", 0.33) colCash = guiGridListAddColumn(gridlist, "Cash", 0.33) for i=1,#Locations do --For loop shows location, distance (rounded to integer) and the cash player will get local x,y,z,text,cash = Locations[i][1],Locations[i][2],Locations[i][3],Locations[i][4],Locations[i][5] local px,py,pz = getElementPosition(localPlayer) --Player position local distance = getDistanceBetweenPoints3D(px,py,pz,x,y,z) --Distance between player and location local row = guiGridListAddRow ( gridlist,text, math.floor(distance), cash ) end btn_acc = guiCreateButton(72, 231, 140, 25, "Accept", false, window) guiSetFont(btn_acc, "sa-header") btn_exit = guiCreateButton(284, 231, 140, 25, "Exit", false, window) guiSetFont(btn_exit, "sa-header") addEventHandler("onClientDoubleClick", root, DoubleClick) --Handler for double click end addEvent("TruckerStart", true) addEventHandler("TruckerStart", getRootElement(), showGUI) function DoubleClick (button) if button == "left" then Name = guiGridListGetItemText(gridlist,guiGridListGetSelectedItem(gridlist),1) --Get the name (Location[4]) outputChatBox(""..Name) --Testing to see if it gets the name --Something to iterate through table and check if the Name is equals to ^"Name"^, then create a marker after it gets the Locations x,y,z from table local marker = createMarker( x,y,z-1,"cylinder", 3, 0, 100, 0, 100 ) end end Any help is appreciated, or even a pointer to a site where it explains how to get 1 row in a table.
  22. @IIYAMA Thanks so much, I was confused if custom handlers were just used within a script nice to know there's an easy way!
  23. He is asking how to make it so Rhino takes more damage, believe it or not... Rhino DOES take damage already! But it takes little damage.... There's a few ways you can mess around with how much damage vehicles take, I recommend you start with SetVehicleHandling and use collisionDamageMultiplier, I do not know if this is just for vehicle collisions, so if your car hits a wall or another car.... But it's a start! If it doesn't work for bullets etc, then maybe think of getting the vehicles health and setting it (as bonus said) with OnVehicleDamage, this will mean you can set health to vehicle health -x where x is the amount you want to subtract from the vehicles health after you get the current health. If you have set Rhinos to be damage proof with another script then just use setVehicleDamageProof(vehicle, false) where vehicle is the Rhino. Hope this helped! Can always try make a function if you're still struggling.
  24. I have a script for a job which spawns a marker, but when my player changes team I want to be able to destroy that marker, I know one way is make a command in each resource to set the players team to nil, then if the player is not in the team from that resource, just return the script, but it get's annoying for players because they have to type that command and leave their team all the time... So my question is, does anyone know of a handler that's triggered when a player changes team? If not... is there a way to add a custom event and trigger it across different resources? For example, if I made 2 resources, Resource 1 and Resource 2 and I added a triggerClientEvent in Resource 1 for a custom event in Resource 2, it would be able to find the custom event in resource 2 and execute it... Basically I want to find a way to trigger a custom event outwith the resource.
×
×
  • Create New...