-
Posts
2,753 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Captain Cody
-
Yet another issue... God, I suck at scripting.
Captain Cody replied to Captain Cody's topic in Scripting
Here's the entire code jailSystemData = {} ---Jails player if they are wanted, and are hit by police with night stick function jailOrNotPlayer (attacker, attackerweapon, bodypart, loss) outputDebugString("function jailOrNotPlayer has been executed") local PoliceTeam = getTeamFromName("Police") local MilitaryTeam = getTeamFromName("Military") if getPlayerTeam ( attacker ) == PoliceTeam or getPlayerTeam ( attacker ) == MilitaryTeam then outputDebugString("Attacker was a cop") local convict = source if (attackerweapon == 3) then outputDebugString("So and so was hit with night stick") level = getPlayerWantedLevel ( convict ) if level > 0 then theconvictName = getPlayerName (convict) outputChatBox ( "You have been jailed, do /jailtime to get time remaining.", convict ) outputChatBox ( "You have jailed" ..theconvictName.."." , attacker ) setElementInterior ( convict, 6, 264.05957, 77.829102, 1001.0391 ) setElementDimension ( convict, 1 ) jailSystemData[convict] = {} local playerjailSystemData = jailSystemData[convict] playerjailSystemData["injail"] = true outputDebugString("Person jailed") jailedperson = convict local theTimer = setTimer(function() end, (level * 40000), 1,convict) playerjailSystemData["timer"] = theTimer setTimer ( function() -- setElementInterior ( jailedperson, 0, 1541.3105, -1675.4785, 13.552299 ) setElementDimension ( jailedperson, 0 ) outputChatBox ( "You have been released.", jailedperson ) outputDebugString("Person Released from jail.") setPlayerWantedLevel ( jailedperson, 0 ) local playerjailSystemData = jailSystemData[jailedperson] playerjailSystemData["injail"] = false local convict = jailedperson end, (level * 40000), 1 ) end end end end --Should set timer on spawn to release player if they were in jail before they left function checkIfJailed () local playerjailSystemData = jailSystemData[source] if playerjailSystemData then if playerjailSystemData["injail"] then thejailedperson = source outputChatBox ( "You are in jail do /jailtime to get amount of time remaining.", thejailedperson ) local theTimer = setTimer(function() end, (level * 40000), 1,convict) setTimer ( function() -- setElementInterior ( thejailedperson, 0, 1541.3105, -1675.4785, 13.552299 ) setElementDimension ( thejailedperson, 0 ) outputChatBox ( "You have been released", thejailedperson ) outputDebugString("Person Released from jail.") setPlayerWantedLevel ( thejailedperson, 0 ) local playerjailSystemData = jailSystemData[thejailedperson] playerjailSystemData["injail"] = false playerjailSystemData["timer"] = theTimer end, (level * 40000), 1 ) end end end --Function for command /jailtime, shows the player how long they have left function checkHisTime () local playerjailSystemData = jailSystemData[source] if playerjailSystemData then local theTimer = playerjailSystemData["timer"] local remaining = getTimerDetails(theTimer) if (remaining) then outputChatBox("You have: "..remaining.." millisecounds remaining.", source) else outputChatBox("You are not in jail.", source) end end end --Event and command handlers addEventHandler ( "onPlayerDamage", getRootElement (), jailOrNotPlayer ) addCommandHandler ( "jailtime", checkHisTime ) addEventHandler ( "onPlayerJoin", getRootElement(), checkIfJailed ) Tad bit long but there's the whole thing. -
Yet another issue... God, I suck at scripting.
Captain Cody replied to Captain Cody's topic in Scripting
#1 Not sure what you mean by that but What start the functions are addEventHandler ( "onPlayerDamage", getRootElement (), jailOrNotPlayer ) addCommandHandler ( "jailtime", checkHisTime ) addEventHandler ( "onPlayerJoin", getRootElement(), checkIfJailed ) #2 fixed -
Yet another issue... God, I suck at scripting.
Captain Cody replied to Captain Cody's topic in Scripting
I added the stuff to a table so I can figureout whos in jail or not Here's what declares the table start jailSystemData = {} Here's what assigns a table to the player jailSystemData[source] = {} local playerjailSystemData = jailSystemData[source] playerjailSystemData["Injail"] = true local theTimer = setTimer(function() end, (level * 40000), 1) playerjailSystemData["timer"] = theTimer Here's what pulls the data for another function local playerjailSystemData = jailSystemData[source] if playerjailSystemData then It's not finding the data for the player, returns nil -
Yet another issue... God, I suck at scripting.
Captain Cody replied to Captain Cody's topic in Scripting
Edited it after I figured out how to do it. -
Yet another issue... God, I suck at scripting.
Captain Cody replied to Captain Cody's topic in Scripting
--Ah nvm found it-- -
Yet another issue... God, I suck at scripting.
Captain Cody replied to Captain Cody's topic in Scripting
Well what I mean by debug is errors in debug-script, but I'll add those and see if I can find the issue -
function jailOrNotPlayer (attacker, attackerweapon, bodypart, loss) local PoliceTeam = getTeamFromName("Military, Police") if getPlayerTeam ( attacker ) == PoliceTeam then local convict = source if (attackerweapon == 3) then local level = getPlayerWantedLevel ( convict ) if level > 0 then outputChatBox ( "You have been jailed", convict ) setElementInterior ( convict, 6, 264.05957, 77.829102, 1001.0391 ) setTimer ( function(convict) -- setElementInterior ( convict, 0, 1541.3105, -1675.4785, 13.552299 ) outputChatBox ( "You have been released", convict ) initalwantedlevel = getPlayerWantedLevel ( convict ) local wantedlevelaa = (initalwantedlevel * 200) setPlayerWantedLevel ( convict, 0 ) end, wantedlevelaa, 1 ) end end end end addEventHandler ( "onPlayerDamage", getRootElement (), jailOrNotPlayer ) Should jail player, showing no signs at all of jailing the player, nothing showing in debugscript
-
1)Player hits marker 2)If players engine is on, it alerts him to turn it off 3)It checks if engine is off 4)If not it keeps checking --What I originally planned to replace this with is when the player presses space it checks, if not alerts driver to turn engine off, if so it continues. / --Which ever would be easier, first option or this./ 5)If it is off, it refuels the vehicle 6)After vehicle is fully refueled it alerts the driver.
-
Ok scratch that, to over kill. How would I make it so when you hit and your engine is on it outputs chat box "Already have" then when you turn off engine it refuels? --Gas station refuel-- function vehicleRefuel(v,m) if not getElementData(m,'gasStation') then return end if getElementType(v) ~= 'vehicle' then return end if getVehicleType(v) ~= 'Automobile' and getVehicleType(v) ~= 'Bike' and getVehicleType(v) ~= 'Monster Truck' and getVehicleType(v) ~= 'Quad' and getVehicleType(v) ~= 'Plane' and getVehicleType(v) ~= 'Boat' and getVehicleType(v) ~= 'Helicopter' then return end local driver = getVehicleOccupants(v);w if getVehicleEngineState ( v ) then outputChatBox("Press J or do /engine to turn engine off.",getVehicleController(v), 255, 255, 255); return end if not driver[0] then return end if not isElementWithinMarker(v,m) then return end --### local maxFuel = carFuel[0]; if getPlayerMoney(driver[0]) < 25 then outputChatBox("You cannot afford any more fuel.",getVehicleController(v), 255, 255, 255); return end if carFuel[getElementModel(v)] then maxFuel = carFuel[getElementModel(v)]; end if getCarFuel(v) >= maxFuel then return end addCarFuel(v,15); takePlayerMoney(driver[0],25); if getCarFuel(v) >= maxFuel then outputChatBox("Your vehicle has been 100% refueled.",getVehicleController(v), 255, 255, 255); takeCarFuel(v,getCarFuel(v)-maxFuel); return end setTimer(vehicleRefuel,500,1,v,m); end addEventHandler('onVehicleRefuel',getRootElement(),vehicleRefuel); function hitTheMarker(e) setTimer(vehicleRefuel,1500,1,e,source); end addEventHandler('onMarkerHit',getRootElement(),hitTheMarker); --Station refuel--
-
How would I get it so on hit marker it activates the refuel function and what not.
-
What would I use to make it so when you hit the marker, turn off your engine and press space, it starts refueling?
-
This should refuel vehicle when the engine is off and the driver hits space, no debugerrors but I know I did it wrong because it aint working here's the code function vehicleRefuel(v,m) if not getElementData(m,'gasStation') then return end if getElementType(v) ~= 'vehicle' then return end if getVehicleType(v) ~= 'Automobile' and getVehicleType(v) ~= 'Bike' and getVehicleType(v) ~= 'Monster Truck' and getVehicleType(v) ~= 'Quad' and getVehicleType(v) ~= 'Plane' and getVehicleType(v) ~= 'Boat' and getVehicleType(v) ~= 'Helicopter' then return end local driver = getVehicleOccupants(v); if not driver[0] then return end if getVehicleEngineState(v) then outputChatBox("Please turn your engine off with j, or /engine then hitspace to refuel.",driver[0]); return end addEventHandler( "onClientKey", root, function(button,press) if (press) and button == "space" then if not isElementWithinMarker(v,m) then return end local maxFuel = carFuel[0]; if getPlayerMoney(driver[0]) < 25 then outputChatBox("You can't afford any more fuel.",p); return end if carFuel[getElementModel(v)] then maxFuel = carFuel[getElementModel(v)]; end if getCarFuel(v) >= maxFuel then return end addCarFuel(v,15); takePlayerMoney(driver[0],25); if getCarFuel(v) >= maxFuel then outputChatBox("Your vehicle has been fully refueled.",getVehicleController(v), 255, 255, 255); takeCarFuel(v,getCarFuel(v)-maxFuel); return end setTimer(vehicleRefuel,500,1,v,m); return true end return false end ) end addEventHandler('onVehicleRefuel',getRootElement(),vehicleRefuel); function hitTheMarker(e) setTimer(vehicleRefuel,1500,1,e,source); end addEventHandler('onMarkerHit',getRootElement(),hitTheMarker); Any ideas?
-
You have spike set to local, try removing "Local" and try.
-
What line was the debug script giving you as messed up?
-
Create tables here's a guide I got while creating my trucking script. 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. When you start this job, you do this: truckerJobData[player] = {} You use the player as key of the table. Which is between the brackets > [ ]. 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] 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 ) 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. 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 Replace what you need. But there's a basic guide from IIYAMA
-
Accually now that I look at it, remove hitElement completely.
-
Change [hitElement] To hitElement and add a comma before.
-
--Nvm ignore what was here, problem sovled--
-
ok that fixed it, but another question how would I go about adding money to the total pay if the mission were illegal here's what defines if he did legal mission or not - when he enters the Illegal marker playerTruckerJobData["Illegal"] = true Here's what increases the pay local payaddon = if playerTruckerJobData["Illegal"] = true then 5000 else 0 Did not do the increase pay right, but I'm not sure how to accually do it.
-
Or so I thought function destroyVehicle (PlayerAb) local playerTruckerJobData = truckerJobData[playerAb] --destroyThings local truckMain = playerTruckerJobData["vehicle"] local trailerAb = playerTruckerJobData["trailer"] local finishPoint = playerTruckerJobData["marker"] local blip = playerTruckerJobData["blip"] --removeEventHandlers removeEventHandler ("onVehicleExit", truckMain, vehicleExit) removeEventHandler ("onPlayerQuit", playerAb, onQuit) removeEventHandler ("onMarkerHit", finishPoint , endTheMission) destroyElement (trailerAb) destroyElement (finishPoint) destroyElement(blip) truckerJobData[playerAb] = nil end end end Gives me debug, expected -> End of script at line "125" the end of this.
-
Ok thank you. Everything on the script works correctly now.
-
That worked, but do you know the issue with the on vehicle leave -- "All the script that's connected to on vehicle leave" function destroyVehicle () if destroyTimer then 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 end function vehicleExit (PlayerAb) local playerTruckerJobData = truckerJobData[player] if playerTruckerJobData then --destroyThings local truckMain = playerTruckerJobData["vehicle"] if source == truckMain then outputChatBox ("Go back to the truck within a minute", PlayerAb, 255, 255, 255, true) destroyTimer = setTimer (destroyVehicle, 600000, 1) addEventHandler ("onVehicleEnter", truckMain, destrTimer) else return false end end end function destrTimer (thePlayer) local playerTruckerJobData = truckerJobData[player] if playerTruckerJobData then --destroyThings local truckMain = playerTruckerJobData["vehicle"] if source == truckMain and thePlayer == playerAb then local team = getPlayerTeam (thePlayer) if getTeamName (team) == "Other" or getTeamName (team) == "Police" then return false else killTimer (destroyTimer) removeEventHandler ("onVehicleEnter", truckMain, destrTimer) setVehicleLocked (truckMain, true) end else return false end end end
-
How would I call it from another function?
-
Here's the whole server side script, any idea what's wrong with it? --//Tables and other stuff tableLocationsX = {} tableLocationsY = {} tableLocationsZ = {} trailerType = {} truckerJobData = {} --//Cords for Blip BlipX = -241.99414 BlipY = -226.80957 BlipZ = 2.1505408 --//Cords for Trailer TrailerX = -208.95801 TrailerY = -211.38281 TrailerZ = 1.421875 TrailerRotation = 0 --//Cords for Blip/Marker MarkerX = -227.02539 MarkerY = -243.80469 MarkerZ = 1.421875 tableMoney = {} locationCount = 3 --//Location 1 tableLocationsX[1] = 2253.7 tableLocationsY[1] = -84.0 tableLocationsZ[1] = 25.3 tableMoney[1] = 500 trailerType[1] = 500 --//Location 2 tableLocationsX[2] = 1093.7 tableLocationsY[2] = -931.6 tableLocationsZ[2] = 41.9 tableMoney[2] = 550 trailerType[2] = 500 --//Location3 tableLocationsX[3] = -47.3 tableLocationsY[3] = -1137.5 tableLocationsZ[3] = 0.07 tableMoney[3] = 500 trailerType[3] = 500 function startScript () StartBlip = createBlip (MarkerX , MarkerY , MarkerZ , 42 ) setBlipVisibleDistance(StartBlip, 220) addEvent( "startTheMission", true ) rootElement = getRootElement() addEventHandler ("startTheMission", rootElement, startMission) TruckDriverAA = getTeamFromName("Trucker") NoJob = getTeamFromName("Unemployed") end function startMission () --Pick up Trailer and start job marker markerAAB = createMarker ( MarkerX , MarkerY , MarkerZ ) addEventHandler ("onMarkerHit", markerAAB, startMissionAAA) end function startMissionAAA ( hitElement ) if getElementType ( hitElement ) == "vehicle" and getVehicleOccupant ( hitElement ) then local truckMain = hitElement playerAb = getVehicleOccupant ( hitElement ) truckerJobData[playerAb] = {} local playerTruckerJobData = truckerJobData[playerAb] local TrailerAb = createVehicle (435, TrailerX, TrailerY, TrailerZ, 0, TrailerRotation, trailerType[randomLoc]) setVehicleVariant (TrailerAb, 5, 0) attachTrailerToVehicle ( truckMain, TrailerAb ) setPlayerTeam ( playerAb, TruckDriverAA ) destroyElement (markerAAB) --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"] = TrailerAb else return false end end function destroyVehicle () if destroyTimer then 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 end function vehicleExit (PlayerAb) local playerTruckerJobData = truckerJobData[player] if playerTruckerJobData then --destroyThings local truckMain = playerTruckerJobData["vehicle"] if source == truckMain then outputChatBox ("Go back to the truck within a minute", PlayerAb, 255, 255, 255, true) destroyTimer = setTimer (destroyVehicle, 600000, 1) addEventHandler ("onVehicleEnter", truckMain, destrTimer) else return false end end end function destrTimer (thePlayer) local playerTruckerJobData = truckerJobData[player] if playerTruckerJobData then --destroyThings local truckMain = playerTruckerJobData["vehicle"] if source == truckMain and thePlayer == playerAb then local team = getPlayerTeam (thePlayer) if getTeamName (team) == "Other" or getTeamName (team) == "Police" then return false else killTimer (destroyTimer) removeEventHandler ("onVehicleEnter", truckMain, destrTimer) setVehicleLocked (truckMain, true) end else return false end end end 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 function endTheMission ( hitElement ) if getElementType ( hitElement ) == "Vehicle" then local playerAbb = getVehicleOccupant ( hitElement ) local playerTruckerJobData = truckerJobData[playerAbb] local truckMain = playerTruckerJobData["vehicle"] if getElementType ( hitElement ) == "truckMain" then if playerTruckerJobData and playerTruckerJobData["marker"] == source then -- Check if all data is correct. outputDebugString("endTheMission") local randomMoney = (tonumber(tableMoney[randomLoc])) outputChatBox ("This load got you " .. randomMoney .. "$ If you would like to continue head back to one of the trucking depos.", playerAbb, 255, 255, 255, true) givePlayerMoney (playerAbb, randomMoney) setPlayerTeam ( playerAbb, 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) truckerJobData[playerAb] = nil -- clean up -- the clean up -- ------------------ end end end end addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), startScript) -- Client side button push creates marker-- --Person hits marker in vehicle "Truck"-- --It detects the truck and player-- --Attaches trailer to the truck-- --Delivery blip and marker apear-- --Person delivers trailer to location-- --It gives the player cash, then removes trailer, blip, marker etc. ----Debug script = attempt to index local "PlayerTruckJobData (A nil Value)
