Jump to content

AfuSensi

User Guide Contributor
  • Posts

    59
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by AfuSensi

  1. If i don't, i'll get this error: viewtopic.php?f=91&t=77650 Nonsense. It's not even about the function table. You are assigning a marker element to the global variable, that means you can use directly createdmarker. If you still want to use the _G global table, then use it like that: _G["createdmarker"] I'm sorry, i got it confused with randomfunctionfromtable. Removed it. This gives me the error: Bad 'ped' pointer @ 'isPlayerInVehicle' . function hittingthemarker ( hitElement ) local randomfunctionfromtable = functionstable[math.random(1,#functionstable)] if isPlayerInVehicle( hitElement ) then setTimer (_G[randomfunctionfromtable], 50, 1) sx,sy,sz = getElementPosition(source) destroyElement(source) end end addEventHandler('onMarkerHit', getRootElement(), hittingthemarker)
  2. If i don't, i'll get this error: viewtopic.php?f=91&t=77650
  3. Thanks, i got the source part working, Now the only thing that still needs fixing is to let the even trigger once. function hittingthemarker ( hitElement ) local randomfunctionfromtable = functionstable[math.random(1,#functionstable)] if getElementType( hitElement ) == "player" then if isPlayerInVehicle( hitElement ) then setTimer (_G[randomfunctionfromtable], 50, 1) sx,sy,sz = getElementPosition(source) setElementPosition ( source, 0,0,0) -- makes marker go away -- disappearedmarker = source -- targets the marker that went away -- setTimer (function () setElementPosition(disappearedmarker, sx,sy,sz) end, respawntime, 1) -- makes marker come back, set respawn time at top of the script -- end end end addEventHandler('onMarkerHit', getRootElement(), hittingthemarker) If anyone could guide me on this, it would be greatly appreciated.
  4. Hi all, I got two questions about markers. Q1: When i ride trough a marker, the event 'onMarkerHit' fires twice. I have no idea what's wrong with it. Function that hits twice: function hittingthemarker ( hitElement ) local randomfunctionfromtable = functionstable[math.random(1,#functionstable)] if getElementType( hitElement ) == "player" then if isPlayerInVehicle( hitElement ) then setTimer (_G[randomfunctionfromtable], 50, 1) setElementPosition (_G[createdmarker], 0,0,0) end end end addEventHandler('onMarkerHit', getRootElement(), hittingthemarker) Q2: How can i detect what marker the player drove trough? I am creating the markers via a loop trough the objects, so search for a certain objects for the cordinations. function checkforheads () -- Checks for heads, replaces it with markers and makes the heads invisible and with no collision -- for _, t in pairs( allObjects ) do if ( getElementModel (t) == 2908 ) then x,y,z = getElementPosition (t) -- Gets xyz position from the heads createdmarker = createMarker (x, y, z, "cylinder", markersize, 0, 255, 0, 150) -- Creates the markers setElementAlpha ( t, 0 ) setElementCollisionsEnabled(t, false) end end end addEventHandler ( "onResourceStart", getRootElement(), checkforheads ) I want the marker to move if a player drove trough it ( setElementPosition ), but it seems that there is no way to detect what marker the player drove trough, only IF the player drove trough a marker. If i do this: function hittingthemarker ( hitElement ) local randomfunctionfromtable = functionstable[math.random(1,#functionstable)] if getElementType( hitElement ) == "player" then if isPlayerInVehicle( hitElement ) then setTimer (_G[randomfunctionfromtable], 50, 1) setElementPosition (_G[createdmarker], 0,0,0) end end end addEventHandler('onMarkerHit', getRootElement(), hittingthemarker) It gives an error : 'Bad argument @ 'setElementPosition' [Expected element at argument 1, got nil]' Here is my full script (server) : markersize = 2 -- Set Marker Size -- respawntime = 10000 -- Set marker respawn time in milliseconds ( 1sec = 1000 ) -- functionstable = { "MassiveCar", "Barrel", "Haybale", "Rocket" } allObjects = getElementsByType ( "object" ) function destroyothermarkers () -- Destroys all markers that are not from this script -- previousmarkers = getElementsByType ("marker") for _, prevmark in pairs( previousmarkers ) do destroyElement ( prevmark ) end end addEventHandler ( "onResourceStart", getRootElement(), destroyothermarkers ) function checkforheads () -- Checks for heads, replaces it with markers and makes the heads invisible and with no collision -- for _, t in pairs( allObjects ) do if ( getElementModel (t) == 2908 ) then x,y,z = getElementPosition (t) -- Gets xyz position from the heads createdmarker = createMarker (x, y, z, "cylinder", markersize, 0, 255, 0, 150) -- Creates the markers setElementAlpha ( t, 0 ) setElementCollisionsEnabled(t, false) end end end addEventHandler ( "onResourceStart", getRootElement(), checkforheads ) function MarkerColorChange () -- Random Colors for the markers allMarkers = getElementsByType ("marker") for _, mrkr in pairs( allMarkers ) do if ( getMarkerSize (mrkr) == markersize ) then setTimer (function() setMarkerColor ( mrkr, math.random (0,255), math.random (0,255), math.random (0,255), 80 ) end, 150, 0 ) end end end addEventHandler ( "onResourceStart", getRootElement(), MarkerColorChange ) --------------------HIT FUNCTIONS----------------- function MassiveCar () outputChatBox ("MassiveCar Function") end function Barrel () outputChatBox ("Barrel Function") end function Haybale () outputChatBox ("Haybale Function") end function Rocket () outputChatBox("Rocket Function") end -------------------END HIT FUNCTIONS------------- function hittingthemarker ( hitElement ) local randomfunctionfromtable = functionstable[math.random(1,#functionstable)] if getElementType( hitElement ) == "player" then if isPlayerInVehicle( hitElement ) then setTimer (_G[randomfunctionfromtable], 50, 1) setElementPosition (_G[createdmarker], 0,0,0) end end end addEventHandler('onMarkerHit', getRootElement(), hittingthemarker)
  5. Hi everyone, I am trying to create a script where if you hit a marker, a random function will get triggered. Now i stored my function names in a table, and added a function with the event onMarkerHit. But every time i ride trough a marker, debugscript gives me this error: Bad argument @ 'setTimer' [Expected function at argument 1, got table]. My question is, how do i properly randomize the function name table, and start the function the randomizer chose? My script(server): markersize = 2 -- Set Marker Size -- respawntime = 10000 -- Set marker respawn time in milliseconds ( 1sec = 1000 ) -- functionstable = { [1]={"MassiveCar"}, [2]={"Barrel"}, [3]={"Haybale"}, [4]={"Rocket"}, } allObjects = getElementsByType ( "object" ) function destroyothermarkers () -- Destroys all markers that are not from this script -- previousmarkers = getElementsByType ("marker") for _, prevmark in pairs( previousmarkers ) do destroyElement ( prevmark ) end end -- setTimer ( destroyothermarkers, 1000, 1 ) addEventHandler ( "onResourceStart", getRootElement(), destroyothermarkers ) function checkforheads () -- Checks for heads, replaces it with markers and makes the heads invisible and with no collision -- for _, t in pairs( allObjects ) do if ( getElementModel (t) == 2908 ) then x,y,z = getElementPosition (t) -- Gets xyz position from the heads createdmarker = createMarker (x, y, z, "cylinder", markersize, 0, 255, 0, 150) -- Creates the markers setElementAlpha ( t, 0 ) setElementCollisionsEnabled(t, false) end end end addEventHandler ( "onResourceStart", getRootElement(), checkforheads ) -- setTimer ( checkforheads, 1000, 1 ) function MarkerColorChange () -- Random Colors for the markers allMarkers = getElementsByType ("marker") for _, mrkr in pairs( allMarkers ) do if ( getMarkerSize (mrkr) == markersize ) then setTimer (function() setMarkerColor ( mrkr, math.random (0,255), math.random (0,255), math.random (0,255), 80 ) end, 150, 0 ) end end end -- setTimer ( MarkerColorChange, 1000, 1 ) addEventHandler ( "onResourceStart", getRootElement(), MarkerColorChange ) --------------------HIT FUNCTIONS----------------- function MassiveCar () outputChatBox ("MassiveCar Function") end function Barrel () outputChatBox ("Barrel Function") end function Haybale () outputChatBox ("Haybale Function") end function Rocket () outputChatBox("Rocket Function") end -------------------END HIT FUNCTIONS------------- function hittingthemarker ( hitElement ) local randomfunctionfromtable = functionstable[math.random(1,#functionstable)] if getElementType( hitElement ) == "player" then if isPlayerInVehicle( hitElement ) then setTimer (randomfunctionfromtable, 50, 1) end end end addEventHandler('onMarkerHit', getRootElement(), hittingthemarker) EDIT: i rewrote my table to: functionstable = { 'MassiveCar', 'Barrel', 'Haybale', 'Rocket' } Now instead of giving me the error: Expected function at argument 1, got table, it gives me the error "expected function at argument 1, got string 'string' "
  6. Thanks guys! I got it working! lane1pos = 4921.2001953125 --Put x cordinate of lane 1 here. lane2pos = 4931.7001953125 --Put x cordinate of lane 2 here. lane3pos = 4941.7998046875 --Put x cordinate of lane 3 here. spacing = 6 --Put your spacing here (the amount of space each lane counts.) function autodrive () toggleControl ( "vehicle_left", false ) -- disable the vehicle_left key toggleControl ( "vehicle_right", false ) -- disable the vehicle_right key toggleControl ( "accelerate", false ) -- disable the accelerate key toggleControl ( "vehicle_fire", false ) -- disable fire for NOS toggleControl ( "brake_reverse", false ) -- disable the brake_reverse key toggleControl ( "handbrake", false ) -- disable the handbrake key setControlState ( "accelerate", true ) -- force the accelerate key on setControlState ( "vehicle_fire", true ) -- force the fire (nos) key on end addEventHandler ( "onClientPreRender", root, autodrive ) function links () local veh = getPedOccupiedVehicle(localPlayer) if (isVehicleBlown( veh ) == false) then local sx,sy,sz = getElementPosition ( veh ) if ( lane1pos - spacing < sx ) and ( lane1pos + spacing > sx ) then setElementPosition( veh, lane1pos, sy, sz + 0.05 ) outputChatBox ("lanepos1 links") elseif ( lane2pos - spacing < sx ) and ( lane2pos + spacing > sx ) then setElementPosition( veh, lane1pos, sy, sz + 0.05 ) outputChatBox ("lanepost2 links") elseif ( lane3pos - spacing < sx ) and ( lane3pos + spacing > sx ) then setElementPosition( veh, lane2pos, sy, sz + 0.05 ) outputChatBox ("lanepost2 links 2") end end end bindKey ( "Q", "down", links ) function rechts () local veh = getPedOccupiedVehicle(localPlayer) if (isVehicleBlown( veh ) == false) then local sx,sy,sz = getElementPosition ( veh ) if ( lane1pos - spacing < sx ) and ( lane1pos + spacing > sx ) then setElementPosition( veh, lane2pos, sy, sz + 0.05 ) outputChatBox ("lanepost2 rechts") elseif ( lane2pos - spacing < sx ) and ( lane2pos + spacing > sx ) then setElementPosition( veh, lane3pos, sy, sz + 0.05 ) outputChatBox ("lanepost3 rechts") elseif ( lane3pos - spacing < sx ) and ( lane3pos + spacing > sx ) then setElementPosition( veh, lane3pos, sy, sz + 0.05 ) outputChatBox ("lanepost3 rechts2") end end end bindKey ( "E", "down", rechts ) For some reason i had to call it local otherwise it would give me the same error. If anyone can explain that, i would appreciate it!
  7. Hey, I am an incredible noob at lua coding, but im trying to become better at it. So i am trying to create a 3 lane system like (with bound keys "Q" for jumping to left, and "E" for jumping to right. /debugscript is saying i have a bad argument @ 'getElementPosition' at line 3. This is my script (client): thePlayer = localPlayer vehicle = getPedOccupiedVehicle ( thePlayer ) sx,sy,sz = getElementPosition( vehicle ) lane1pos = 4941.7998046875 --Put x cordinate of lane 1 here. lane2pos = 4931.7001953125 --Put x cordinate of lane 2 here. lane3pos = 4921.2001953125 --Put x cordinate of lane 3 here. bindKey ( "Q", "down", "links" ) function links () if sx == ( lane1pos ) then setElementPosition( vehicle , lane1pos, sy, sz + 0.05 ) outputChatBox ("lanepos1") elseif ( sx == lanepos2 ) then setElementPosition( vehicle , lane1pos, sy, sz + 0.05 ) elseif ( sx == lanepos3 ) then setElementPosition( vehicle , lane2pos, sy, sz + 0.05 ) end end bindKey ( "E", "down", "rechts" ) function rechts () if sx == ( lane1pos ) then setElementPosition( vehicle , lane2pos, sy, sz + 0.05 ) elseif ( sx == lanepos2 ) then setElementPosition( vehicle , lane3pos, sy, sz + 0.05 ) elseif ( sx == lanepos3 ) then setElementPosition( vehicle , lane3pos, sy, sz + 0.05 ) end end I am not asking for anyone to fix my script, just to tell me what's wrong with it, otherwise i won't learn. Thanks!
×
×
  • Create New...