shaio Posted August 19, 2016 Share Posted August 19, 2016 local players = {} addEventHandler("onResourceStart",getRootElement(),function() for _,plr in pairs(getElementsByType("player")) do bindKey(plr,"k","down","lock") end end) addEventHandler("onPlayerJoin",getRootElement(),function() bindKey(source,"k","down","lock") end) function spawnCar(player,cmd,vehicle,value1) if (isPedInVehicle(player) == true) then if getPedOccupiedVehicle(player) and getPedOccupiedVehicleSeat(player) == 0 then local occupiedCar = getPedOccupiedVehicle(player) destroyElement(occupiedCar) local x,y,z = getElementPosition(player) local dim = getElementDimension(player) local int = getElementInterior(player) local s = getVehicleModelFromName(vehicle) if (s == 425) or (s == 520) or (s == 432) then outputChatBox("This vehicle is not allowed!",player,255,0,0) return else if (vehicle == "super" and value1 == "gt") then local car = createVehicle(506,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end elseif (vehicle == "blista" and value1 == "compact") then local car = createVehicle(496,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end else local car = createVehicle(s,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end end end else outputChatBox("You need to get out of your current vehicle!",player,0,255,255) end else local x,y,z = getElementPosition(player) local dim = getElementDimension(player) local int = getElementInterior(player) local s = getVehicleModelFromName(vehicle) if (s == 425) or (s == 520) or (s == 432) then outputChatBox("This vehicle is not allowed!",player,255,0,0) return else if (vehicle == "super" and value1 == "gt") then local car = createVehicle(506,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end elseif (vehicle == "blista" and value1 == "compact") then local car = createVehicle(496,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end else local car = createVehicle(s,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end end end end end addCommandHandler("vi", spawnCar) function owner(source,cmd) if lock == false then if isPedInVehicle(source) then if players[getPedOccupiedVehicle(source)] then return end local serial = getPlayerSerial(source) players[getPedOccupiedVehicle(source)] = {} table.insert(players[getPedOccupiedVehicle(source)],serial) lock = true outputChatBox("Locked!",source,0,255,255) end else if isPedInVehicle(source) then if not players[getPedOccupiedVehicle(source)] then return end players[getPedOccupiedVehicle(source)] = nil lock = false outputChatBox("Unlocked!",source,0,255,255) end end end addCommandHandler("lock",owner) function assignToAnother(player,cmd,otherPlayer) if isPedInVehicle(player) then local serialOther = getPlayerSerial(getPlayerFromName(otherPlayer)) table.insert(players[getPedOccupiedVehicle(player)],serial) outputChatBox("Vehicle Shared With "..otherPlayer.."!",source,0,255,255) outputChatBox(getPlayerName(player).." has granted you access to their vehicle!",shared,0,255,255) end end addCommandHandler("share", assignToAnother) addEventHandler("onVehicleStartEnter",getRootElement(),function(player,seat) if players[source] then for _,carA in pairs(players[source]) do if seat == 0 then if not carA == getPlayerSerial(player) then cancelEvent() outputChatBox("This vehicle is locked!",player,0,255,255) end end end end end) Link to comment
Bonus Posted August 19, 2016 Share Posted August 19, 2016 And WHAT doesn't work? /vi can't work, cause the parameter vehicle and value1 are strings. vehicle isn't a vehicle, it's only a string. /vi Hello my -> vehicle = "Hello", value1 = "my" Link to comment
shaio Posted August 20, 2016 Author Share Posted August 20, 2016 /vi works just fine, i don't have any errors in console or anything in debugscript. I made /vi a long time ago, its the lock system I'm having trouble with.. It gives the messages, but tables just aren't working like they're suppose to. Link to comment
shaio Posted August 20, 2016 Author Share Posted August 20, 2016 My server is posted under every one of my messages/posts, so if u wanna test it, go ahead Link to comment
shaio Posted August 20, 2016 Author Share Posted August 20, 2016 Ok this works, but the /share doesn't work, idk why. Someone help me out local players = {} addEventHandler("onResourceStart",getRootElement(),function() for _,plr in pairs(getElementsByType("player")) do bindKey(plr,"k","down","lock") end end) addEventHandler("onPlayerJoin",getRootElement(),function() bindKey(source,"k","down","lock") end) function spawnCar(player,cmd,vehicle,value1) if (isPedInVehicle(player) == true) then if getPedOccupiedVehicle(player) and getPedOccupiedVehicleSeat(player) == 0 then local occupiedCar = getPedOccupiedVehicle(player) destroyElement(occupiedCar) local x,y,z = getElementPosition(player) local dim = getElementDimension(player) local int = getElementInterior(player) local s = getVehicleModelFromName(vehicle) if (s == 425) or (s == 520) or (s == 432) then outputChatBox("This vehicle is not allowed!",player,255,0,0) return else if (vehicle == "super" and value1 == "gt") then local car = createVehicle(506,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end elseif (vehicle == "blista" and value1 == "compact") then local car = createVehicle(496,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end else local car = createVehicle(s,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end end end else outputChatBox("You need to get out of your current vehicle!",player,0,255,255) end else local x,y,z = getElementPosition(player) local dim = getElementDimension(player) local int = getElementInterior(player) local s = getVehicleModelFromName(vehicle) if (s == 425) or (s == 520) or (s == 432) then outputChatBox("This vehicle is not allowed!",player,255,0,0) return else if (vehicle == "super" and value1 == "gt") then local car = createVehicle(506,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end elseif (vehicle == "blista" and value1 == "compact") then local car = createVehicle(496,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end else local car = createVehicle(s,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end end end end end addCommandHandler("vi", spawnCar) function lock(source,cmd) if lock == false then if isPedInVehicle(source) then if players[getPedOccupiedVehicle(source)] then return end local serial = getPlayerSerial(source) players[getPedOccupiedVehicle(source)] = {} table.insert(players[getPedOccupiedVehicle(source)],serial) lock = true outputChatBox("Locked!",source,0,255,255) end else if isPedInVehicle(source) then if not players[getPedOccupiedVehicle(source)] then return end players[getPedOccupiedVehicle(source)] = nil lock = false outputChatBox("Unlocked!",source,0,255,255) end end end addCommandHandler("lock",lock) function share(player,cmd,otherPlayer) if isPedInVehicle(player) then if (getVehicleOccupant(getPedOccupiedVehicle(player),0) == player) then if players[getPedOccupiedVehicle(player)] then for _,carA in pairs(players[getPedOccupiedVehicle(player)]) do if getPlayerSerial(player) ~= carA then if not getPlayerSerial(getPlayerFromName(otherPlayer)) ~= carA then local serialOther = getPlayerSerial(getPlayerFromName(otherPlayer)) table.insert(players[getPedOccupiedVehicle(player)],serialOther) outputChatBox("Vehicle shared with "..otherPlayer.."!",player,0,255,255) outputChatBox(getPlayerName(player).." has granted you access to their vehicle!",getPlayerFromName(otherPlayer),0,255,255) else local serialOther = getPlayerSerial(getPlayerFromName(otherPlayer)) table.removeValue(players[getPedOccupiedVehicle(player)],serialOther) outputChatBox("Vehicle unshared with "..otherPlayer.."!",player,0,255,255) outputChatBox(getPlayerName(player).." has denied you access to their vehicle!",getPlayerFromName(otherPlayer),0,255,255) end end end end else outputChatBox("You need to be the driver!",player,255,0,0) end end end addCommandHandler("share",share) addEventHandler("onVehicleStartEnter",getRootElement(),function(player,seat) if players[source] then if not (getElementData(player,"passenger") == "allowed") then for _,carA in pairs(players[source]) do if player ~= carA then cancelEvent() outputChatBox("This vehicle is locked!",player,0,255,255) end end else if seat == 0 then cancelEvent() outputChatBox("This vehicle is locked!",player,0,255,255) else return end end end end) function allow(player,cmd,other) if isPedInVehicle(player) then if (getVehicleOccupant(getPedOccupiedVehicle(player),0) == player) then if (getElementData(getPlayerFromName(other),"passenger") == "disallowed") or (getElementData(getPlayerFromName(other),"passenger") == nil) then setElementData(getPlayerFromName(other),"passenger","allowed") outputChatBox(other.." is now allowed to get in as a passenger!",player,0,255,255) outputChatBox(getPlayerName(player).." has allowed you to get in their car as a passenger!",getPlayerFromName(other),0,255,255) else setElementData(getPlayerFromName(other),"passenger","disallowed") outputChatBox(other.." is now disallowed to get in as a passenger!",player,0,255,255) outputChatBox(getPlayerName(player).." has disallowed you to get in their car as a passenger!",getPlayerFromName(other),0,255,255) end end end end addCommandHandler("allow",allow) function eject(player,cmd,other) if isPedInVehicle(player) then if getVehicleOccupant(getPedOccupiedVehicle(player),0) == player then removePlayerFromVehicle(getPlayerFromName(other)) local x,y,z = getElementPosition(getPlayerFromName(other)) setElementPosition(getPlayerFromName(other),x+5,y,z) outputChatBox(getPlayerName(player).." has ejected you from the vehicle!",getPlayerFromName(other),0,255,255) else outputChatBox("You need to be the driver!",player,255,0,0) end end end addCommandHandler("eject",eject) function table.removeValue(table, val) for index, value in ipairs(table) do if value == val then table.remove(table, index) return index end end return false end Link to comment
Simple0x47 Posted August 20, 2016 Share Posted August 20, 2016 Check out debugscript 3 and post the errors it says. And I would thank you if you could post just the /share function and called not predefined functions, thanks. ( I'm on a phone ) Link to comment
shaio Posted August 20, 2016 Author Share Posted August 20, 2016 There are no errors posted in debugscript or console... This is just the share part of the script.. local players = {} function share(player,cmd,otherPlayer) if isPedInVehicle(player) then if (getVehicleOccupant(getPedOccupiedVehicle(player),0) == player) then if players[getPedOccupiedVehicle(player)] then for _,carA in pairs(players[getPedOccupiedVehicle(player)]) do if getPlayerSerial(player) ~= carA then if not getPlayerSerial(getPlayerFromName(otherPlayer)) ~= carA then local serialOther = getPlayerSerial(getPlayerFromName(otherPlayer)) table.insert(players[getPedOccupiedVehicle(player)],serialOther) outputChatBox("Vehicle shared with "..otherPlayer.."!",player,0,255,255) outputChatBox(getPlayerName(player).." has granted you access to their vehicle!",getPlayerFromName(otherPlayer),0,255,255) else local serialOther = getPlayerSerial(getPlayerFromName(otherPlayer)) table.removeValue(players[getPedOccupiedVehicle(player)],serialOther) outputChatBox("Vehicle unshared with "..otherPlayer.."!",player,0,255,255) outputChatBox(getPlayerName(player).." has denied you access to their vehicle!",getPlayerFromName(otherPlayer),0,255,255) end end end end else outputChatBox("You need to be the driver!",player,255,0,0) end end end addCommandHandler("share",share) function table.removeValue(table, val) for index, value in ipairs(table) do if value == val then table.remove(table, index) return index end end return false end Link to comment
Bonus Posted August 20, 2016 Share Posted August 20, 2016 Oh sry, didn't read the /vi function well The shared function got some problems. Try this: addCommandHandler ( "share", function ( player, _, targetname ) -- the parameter-name should describe what the parameter is! if targetname then -- did the player even use a name? local target = getPlayerFromName ( targetname ) if target then -- is the target online? does he even exist? local vehicle = getPedOccupiedVehicle ( player ) if vehicle then -- does the player sit in a vehicle? if getPedOccupiedVehicleSeat ( player ) == 0 then -- is the player the driver -- optional -- if not players[vehicle] then players[vehicle] = {} end --------------- local targetserial = getPlayerSerial ( target ) if players[vehicle][1] then -- the table name is really bad for i=1, #players[vehicle] do -- fastest loop if players[vehicle][i] == targetserial then -- if the targetserial is already in table.remove ( players[vehicle], i ) outputChatBox ( "Vehicle unshared with "..targetname.."!", player, 0, 255, 255 ) outputChatBox ( getPlayerName ( player ).." has denied you access to their vehicle!", 0, 255, 255 ) return -- stop the function HERE end end end -- if the vehicle wasn't shared with target -- players[vehicle][#players[vehicle]+1] = targetserial outputChatBox ( "Vehicle shared with "..targetname.."!", 0, 255, 255 ) outputChatBox ( getPlayerName ( player ).." has granted you access to their vehicle!", 0, 255, 255 ) else outputChatBox ( "You are not the driver of that vehicle", player, 255, 0, 0 ) end else outputChatBox ( "You are not sitting in a vehicle", player, 255, 0, 0 ) end else outputChatBox ( "The target doesn't exist or is offline", player, 255, 0, 0 ) end else outputChatBox ( "Usage: /share [target]", player, 255, 0, 0 ) end end ) Your code was a bit weird. You looped through the table without stopping. In the loop you put the serial in the table, if the serial is already in And removed the serial when it wasn't even in. Link to comment
shaio Posted August 21, 2016 Author Share Posted August 21, 2016 Yes this works, although you set most of the messages up in client-side format. I fixed those Otherwise, works great! Thank you. 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