-
Posts
6,097 -
Joined
-
Last visited
-
Days Won
218
Everything posted by IIYAMA
-
By putting this inside the function you are going to call from. With a valid playerAb element as argument.. startMissionAAA(playerAb)
-
I told you with huge letters not to apply an addEventHandler to the startMissionAAA function. And take over that function correctly.
-
Wtf, that works O_o Thank you very much!
-
Small update on the endTheMission. function endTheMission (truckMain,matchingDimension) if matchingDimension then local playerAb = getVehicleOccupant(truckMain) if playerAb then local playerTruckerJobData = truckerJobData[playerAb] if playerTruckerJobData and playerTruckerJobData["vehicle"] == truckMain and playerTruckerJobData["marker"] == source then -- Check if all data is correct. outputDebugString("endTheMission") local randomMoney = (tonumber(tableMoney[randomLoc]) or 0) outputChatBox ("This load got you " .. randomMoney .. "$ If you would like to continue head back to one of the trucking depos.", playerAb, 255, 255, 255, true) givePlayerMoney (playerAb, randomMoney) setPlayerTeam ( playerAb, NoJob ) ------------------ -- the clean up -- local trailerAb = playerTruckerJobData["trailer"] local blip = playerTruckerJobData["blip"] --removeEventHandlers removeEventHandler ("onVehicleExit", truckMain, vehicleExit) removeEventHandler ("onPlayerQuit", playerAb, onQuit) removeEventHandler ("onMarkerHit", source , endTheMission) --destroyThings if isElement(trailerAb) then -- validate(if is still exist) before destroy destroyElement (trailerAb) end if isElement(blip) then -- validate(if is still exist) before destroy destroyElement (blip) end destroyElement(source) -- destroy the marker, no validate needed. (element used in event, so must exist) destroyElement(truckMain) -- destroy the truck, no validate needed. (element used in event, so must exist) truckerJobData[playerAb] = nil -- clean up -- the clean up -- ------------------ end end end end The onQuit function. function onQuit () local playerTruckerJobData = truckerJobData[source] if playerTruckerJobData then --destroyThings local truckMain = playerTruckerJobData["vehicle"] local trailerAb = playerTruckerJobData["trailer"] local finishPoint = playerTruckerJobData["marker"] local blip = playerTruckerJobData["blip"] --removeEventHandlers removeEventHandler ("onVehicleExit", truckMain, vehicleExit) removeEventHandler ("onPlayerQuit", source, onQuit) removeEventHandler ("onMarkerHit", finishPoint , endTheMission) if isElement(trailerAb) then -- validate(if is still exist) before destroy destroyElement (trailerAb) end if isElement(finishPoint) then -- validate(if is still exist) before destroy destroyElement (finishPoint) end if isElement(blip) then -- validate(if is still exist) before destroy destroyElement(blip) end if isElement(truckMain) then -- validate(if is still exist) before destroy destroyElement(truckMain) end truckerJobData[source] = nil end end The rest you have to do on your own. You have enough inspiration material now.
-
startMissionAAA < execute this function with the player as first argument. Don't add an addEventHandler on this function, but call it from another function(which might have an addEventHandler). function startMissionAAA (playerAb) local truckMain = getPedOccupiedVehicle(playerAb) if truckMain then truckerJobData[playerAb] = {} local playerTruckerJobData = truckerJobData[playerAb] local trailer = createVehicle (435, TrailerX, TrailerY, TrailerZ, 0, TrailerRotation, trailerType[randomLoc]) setVehicleVariant (TrailerAb, 5, 0) attachTrailerToVehicle ( truckMain, TrailerAb ) setPlayerTeam ( playerAb, TruckDriverAA ) --Location stuff-- local randomLoc = math.random (1, locationCount) local finishPoint = createMarker (tableLocationsX[randomLoc], tableLocationsY[randomLoc], tableLocationsZ[randomLoc], "cylinder", 3, 0, 200, 55, 255, playerAb) local blip = createBlip (tableLocationsX[randomLoc], tableLocationsY[randomLoc], tableLocationsZ[randomLoc], 0, 2, 255, 0, 0, 255, 0, 10000, playerAb) --Chat Stuff-- outputChatBox ("Drive to the red blip on the map", playerAb, 255, 255, 255, true) --addEventHandlers addEventHandler ("onVehicleExit", truckMain, vehicleExit) addEventHandler ("onMarkerHit", finishPoint , endTheMission) addEventHandler ("onPlayerQuit", playerAb, onQuit) --Add the stuff into table-- playerTruckerJobData["vehicle"] = truckMain playerTruckerJobData["blip"] = blip playerTruckerJobData["marker"] = finishPoint playerTruckerJobData["trailer"] = trailer else return false end end function endTheMission (truckMain,matchingDimension) if matchingDimension then local playerAb = getVehicleOccupant(truckMain) if playerAb then local playerTruckerJobData = truckerJobData[playerAb] if playerTruckerJobData and playerTruckerJobData["vehicle"] == truckMain and playerTruckerJobData["marker"] == source then -- Check if all data is correct. outputDebugString("endTheMission") local randomMoney = (tonumber(tableMoney[randomLoc]) or 0) outputChatBox ("This load got you " .. randomMoney .. "$ If you would like to continue head back to one of the trucking depos.", playerAb, 255, 255, 255, true) givePlayerMoney (playerAb, randomMoney) setPlayerTeam ( playerAb, NoJob ) ------------------ -- the clean up -- local trailerAb = playerTruckerJobData["trailer"] local finishPoint = playerTruckerJobData["marker"] local blip = playerTruckerJobData["blip"] --removeEventHandlers removeEventHandler ("onVehicleExit", truckMain, vehicleExit) removeEventHandler ("onPlayerQuit", playerAb, onQuit) removeEventHandler ("onMarkerHit", source , endTheMission) --destroyThings if isElement(trailerAb) then -- validate(if is still exist) before destroy destroyElement (trailerAb) end if isElement(finishPoint) then -- validate(if is still exist) before destroy destroyElement (finishPoint) end if isElement(blip) then -- validate(if is still exist) before destroy destroyElement (blip) end destroyElement(source) -- destroy the marker, no validate needed. (element used in event, so must exist) destroyElement(truckMain) -- destroy the truck, no validate needed. (element used in event, so must exist) truckerJobData[playerAb] = nil -- clean up -- the clean up -- ------------------ end end end end
-
What is the best way to get the resource from the resourceRoot element? covert: getResourceRootElement() to getThisResource ( ) --convert: resourceRoot -- to resource I am trying to get the resource from an element in the game. local elementParent = source local elementsThatHaveParents = 0 repeat local elementParent_ = getElementParent ( elementParent ) if elementParent_ and elementParent_ ~= root then elementParent = elementParent_ elementsThatHaveParents = elementsThatHaveParents+1 else elementParent_ = nil end until not elementParent_ https://wiki.multitheftauto.com/wiki/Element_tree And this a workaround which I am not happy about. local theResourceThatOwnsThisElement = false local resourceTable = getResources() for i=1,#resourceTable do local resource = resourceTable[i] if getResourceRootElement(resource) == elementParent then theResourceThatOwnsThisElement = resource break end end
-
Take a look at this resource for inspiration: https://community.multitheftauto.com/in ... ls&id=6177 I used hedit in 2012 to collect the data and wrote that script afterwards.
-
Line 6 and 7. >local RPM = getVehicleRPM(veh)< >setElementData(veh,"RPM",RPM)< Move after: if veh then Line 19: Validate sound with isElement before destroying it. Line 31: Validate the sound with if state, before setting it's volume etc. Line 44: Makes no sense, nilling an location but losing access to the sound element. But what I strongly recommend you, is not using the player as key of the table but the vehicles instead. Use to add and remove from the table: https://wiki.multitheftauto.com/wiki/On ... ntStreamIn and https://wiki.multitheftauto.com/wiki/On ... tStreamOut
-
In a post before I explained exacly how to store and receive data from a table.
-
This is exactly what I meant. function EndTheMission (hitElement) if hitElement == TrailerAb then As I said before, it makes the resource only working for 1 player at the time. When you want more players to be able to use it at the same time, you simply need tables.
-
The random player has no team.
-
onVehicleExit, replace the rootElement with the truck element. onPlayerQuit, replace the rootElement with the player element. And with onMarkerHit you compare inside the function, the hitElement(first argument) with the truck element.
-
If you want to get around that, you will have to assign this job to only player. Doing this by storing it's userdata/player inside a variable and checking it when another player tries to do the same job.
-
because there is only 1 function or well there is only 1 variable that holds that function. But that is not the problem, the problem is with the data. The data is shared between all other players, because it is serverside code.
-
Ask the last question again to yourself. Isn't it obviously with a job resource that more players are using the same variables? If you can't and won't understand the logic of this, then you will be working on a system that can never be used by multiple players. I can't fix something that can't be fixed, sorry.
-
For managing multiply data you need to use tables. For example you start a job for a player. truckerJobData = {} -- declare on top of your script. [/divbox] When you start this job, you do this: truckerJobData[player] = {} You use the player as key of the table. Which is between the brackets > [ ]. I saw tables before in your resource, so you probably already know how they work. You inset an empty table in there, which you can fill up later on. [divbox=#000000] The next step is to redeclare the table in a variable of choice: (this is just a method I like to use) local playerTruckerJobData = truckerJobData[player] [/divbox] After redeclaring the variable that gives access to the empty table, you are going to collect and create the data of the job. This can be the: truck, trailer, blip and marker. local finisha = createMarker (tableLocationsX[randomLoc], tableLocationsY[randomLoc], tableLocationsZ[randomLoc], "cylinder", 3, 0, 200, 55, 255, hitElementa) local blip = createBlip (tableLocationsX[randomLoc], tableLocationsY[randomLoc], tableLocationsZ[randomLoc], 0, 2, 255, 0, 0, 255, 0, 10000, hitElementa) local truckM = createVehicle(514, -715, 963, 12) local trailer = createVehicle ( 435, 0, 0, 4 ) [divbox=#000000] And the last step is to insert the required data of the job, inside your empty table. playerTruckerJobData["blip"] = blip playerTruckerJobData["marker"] = finisha playerTruckerJobData["truck"] = truckM playerTruckerJobData["trailer"] = trailer There are a few ways to do it, but try first this one, because it is easy to read. [/divbox] Ones you did that, you can access your: trailers, trucks, blips and markers very easy. The only thing you need to do is knowing the player/(player-userdata). To access your trailer and destroy it, example: local playerTruckerJobData = truckerJobData[player] if playerTruckerJobData then -- if the player have any job data then ... local trailer = playerTruckerJobData["trailer"] -- then get the trailer element. if isElement(trailer) then -- check if the trailer still does exist in the MTA world. destroyElement(trailer) -- destroy the trailer. end end
-
I am looking at your code and I can figure out some of the issues. Pls ask those questions bellow to yourself: - What happens when you execute the function getRootElement()? - What happens when you attach an addEventHandler with a root element? - What happens when you declare a global variable twice with a different value? For example the variable 'trailer'.
-
You are doing that to yourself, if you are skipping the debug guide. https://wiki.multitheftauto.com/wiki/Debugging Every mistake can be found with that guide.
-
debug the variable banTime... if you want to know which condition you have to use.
-
in ways, yea you can.
-
You can only get it's position: https://wiki.multitheftauto.com/wiki/GetPedBonePosition But you can't actually get them.
-
Line 17.............. .................................................................................................................................. .................................................................................................................................. .................................................................................................................................. .................................................................................................................................. .................................................................................................................................. .................................................................................................................................. ............ Ask him yourself, it is his script. -__-"
-
No, I don't think so. Because the real time never stops, while the ban time is static. function WwW (banPointer, responsibleElement) local player = source local banTime = getBanTime(banPointer) if not banTime then -- ban time isn't specific, so perma ban. setElementData(player, "Data", (getElementData(player, "Data") or 0) + 1) else --local seconds = banTime - getRealTime().timestamp setElementData(player, "Data2", (getElementData(player, "Data2") or 0) + 1) end end addEventHandler ( "onPlayerBan", getRootElement(), WwW )
-
But your main problem is that 'onPlayerBan' doesn't support: seconds, data, additional Only the banPointer and it's responsibleElement. Use ban functions instead: function WwW (banPointer, responsibleElement) local player = source -- The player that gets banned. local seconds = getBanTime(banPointer) - getRealTime().timestamp
-
The element data will directly be removed after the player is banned... It will not even synchronized with the other players in the server because it is a slow transfer.
