at2008 Posted November 16, 2017 Share Posted November 16, 2017 How to create spikes what only punches player's car who in the "robber" team? Link to comment
msyyn Posted November 17, 2017 Share Posted November 17, 2017 (edited) local robberTeams = { ["Robber"] = true } function onStingerHit(hitElement, matchingDimension) if hitElement and matchingDimension then if hitElement:getType() == "vehicle" then local vehicleController = hitElement:getController() or false if vehicleController then local team = vehicleController:getTeam() if not team then return false end if robberTeams[team:getName()] then hitElement:setWheelStates(1, 1, 1, 1) end end end end end Something like this maybe? You would need to attach col shape or marker to the stinger object and then add the "onStingerHit" function to onColShapeHit / onMarkerHit stinger = Object.create(objectID, position, rotation) stingerCol = ColShape.Sphere(position, 2) stingerCol:attach(stinger) stingerCol:setAttachedOffsets(0,0,-0.25) addEventHandler("onColShapeHit", stingerCol, onStingerHit) You can also use this method if you are having multiple stingers: Edited November 17, 2017 by msyyn Link to comment
at2008 Posted November 18, 2017 Author Share Posted November 18, 2017 It's not works for me. Link to comment
at2008 Posted November 18, 2017 Author Share Posted November 18, 2017 addCommandHandler("putaspiketotheground", -- function(player, source) if (player) then local px, py, pz = getElementPosition ( player ) local rz = getPedRotation ( player ) local distance = 5 local x = distance*math.cos((rz+90)*math.pi/180) local y = distance*math.sin((rz+90)*math.pi/180) local b2 = 15 / math.cos(math.pi/180) local nx = px + x local ny = py + y local nz = pz - 0.8 local provz = rz + 90 local spike = createObject ( 2892, nx, ny, nz, 0.0, 0.0, provz) local x, y, z = getElementPosition(player) local x2, y2, z2 = getElementPosition(spike) local blow = createColSphere(x2, y2, z2, 3) addEventHandler("onColShapeHit",blow,function (player) if player and getElementType(player) == "player" then local pveh = getPedOccupiedVehicle(player) if isPedInVehicle(player) then if (getTeamName(getPlayerTeam(player)) ~= "robber" then return false end setVehicleWheelStates(pveh,1,1,1,1) setVehicleColor( pveh, 247, 39, 157 ) end end end) end end) I made this script, but i have an error : WARNING: mypluginsfolder/myplugin.lua:line : Bad argument @ 'getPlayerTeam' [Excepted player at argument 1, got nil] WARNING: mypluginsfolder/myplugin.lua:line : Bad argument @ 'getTeamName' [Excepted player at argument 1, got boolean] --I got these errors from console Link to comment
at2008 Posted November 18, 2017 Author Share Posted November 18, 2017 And this gonna be a police script so I need /cuff(freeze a player) and player carrying (like on this video) and put carried player into a vehicle. Link to comment
Moderators IIYAMA Posted November 18, 2017 Moderators Share Posted November 18, 2017 This code: if (getTeamName(getPlayerTeam(player)) ~= "robber" then return false end Shouldn't be able to executed because of: if player and getElementType(player) == "player" then So I am not sure if I am looking at the right code. Do no attach functions which are inside of other functions directly in an addEventHandler! They are not destroy able without accessing the globals: _G The function will be created infinity times! I recommend you to create a function outside of the block. addCommandHandler("putaspiketotheground", -- function(player, source) if (player) then local px, py, pz = getElementPosition ( player ) local rz = getPedRotation ( player ) local distance = 5 local x = distance*math.cos((rz+90)*math.pi/180) local y = distance*math.sin((rz+90)*math.pi/180) local b2 = 15 / math.cos(math.pi/180) local nx = px + x local ny = py + y local nz = pz - 0.8 local provz = rz + 90 local spike = createObject ( 2892, nx, ny, nz, 0.0, 0.0, provz) local x, y, z = getElementPosition(player) local x2, y2, z2 = getElementPosition(spike) local blow = createColSphere(x2, y2, z2, 3) addEventHandler("onColShapeHit",blow,function (player) if player and getElementType(player) == "player" then local pveh = getPedOccupiedVehicle(player) if isPedInVehicle(player) then if (getTeamName(getPlayerTeam(player)) ~= "robber" then return false end setVehicleWheelStates(pveh,1,1,1,1) setVehicleColor( pveh, 247, 39, 157 ) end end end) end end) 1 Link to comment
at2008 Posted November 18, 2017 Author Share Posted November 18, 2017 Thanks for help, but it says: SCRIPT ERROR: pluginfolder/pluginname.lua:47: ')' expected near 'than' ERROR: Loading script failed: pluginfolder:pluginname.lua:47: expected near 'then' I cant make it to work.. Link to comment
iMr.WiFi..! Posted November 18, 2017 Share Posted November 18, 2017 (edited) Try it : addCommandHandler("putaspiketotheground", function(player, cmd) if (player) then local px, py, pz = getElementPosition ( player ) local rz = getPedRotation ( player ) local distance = 5 local x = distance*math.cos((rz+90)*math.pi/180) local y = distance*math.sin((rz+90)*math.pi/180) local b2 = 15 / math.cos(math.pi/180) local nx = px + x local ny = py + y local nz = pz - 0.8 local provz = rz + 90 local spike = createObject ( 2892, nx, ny, nz, 0.0, 0.0, provz) local x, y, z = getElementPosition(player) local x2, y2, z2 = getElementPosition(spike) local blow = createColSphere(x2, y2, z2, 3) addEventHandler("onColShapeHit",blow, function (element) if element and getElementType(element) == "player" then local pveh = getPedOccupiedVehicle(element) if isPedInVehicle(element) then if ( getTeamName( getPlayerTeam( element ) ) ~= "robber" ) then return end setVehicleWheelStates(pveh, 1, 1, 1, 1) setVehicleColor( pveh, 247, 39, 157 ) end end end ) end end ) Edited November 18, 2017 by iMr.WiFi..! Link to comment
at2008 Posted November 18, 2017 Author Share Posted November 18, 2017 Thenk you so much! It's works fine! Thanks for help! Link to comment
msyyn Posted November 20, 2017 Share Posted November 20, 2017 On 11/18/2017 at 22:04, StevenHN said: Thenk you so much! It's works fine! Thanks for help! Make sure to also store the spikes somewhere so you can delete them when player quits / dies so there won't be 1000 spikes laying around the map Link to comment
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