shaio Posted July 29, 2016 Share Posted July 29, 2016 I've been working on this for a while now, but I think I'm a script kiddie, this works like shit was just thrown together :L Idk how to go any further with it. Is there anyway to enhance this?? function lock(player,cmd) if isPedInVehicle(player) then if getPedOccupiedVehicleSeat(player) == 0 then if (getElementData(getPedOccupiedVehicle(player),"locks") == true) then setElementData(getPedOccupiedVehicle(player),"lock",false) setElementData(getPedOccupiedVehicle(player),"locks",false) setVehicleLocked(getPedOccupiedVehicle(player),false) outputChatBox("Unlocked!",player,0,255,255) else setElementData(getPedOccupiedVehicle(player),"lock",getPlayerSerial(player)) setElementData(getPedOccupiedVehicle(player),"locks",true) outputChatBox("Locked!",player,0,255,255) end else outputChatBox("You are not the driver!",player,0,255,255) end end end addCommandHandler("lock",lock) addEventHandler ("onPlayerJoin", getRootElement(), function() bindKey (source, "k", "down", lock) end) addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), function() local players = getElementsByType ("player") for k, player in ipairs (players) do bindKey (player, "k", "down", lock) end end) function inveh(player,seat,jacked) local accountName = getAccountName(getPlayerAccount(player)) if isObjectInACLGroup("user."..accountName,aclGetGroup("Admin")) or isObjectInACLGroup("user."..accountName,aclGetGroup("SuperModerator")) or isObjectInACLGroup("user."..accountName,aclGetGroup("Moderator"))then return else if not (getElementData(source,"locked") == getPlayerSerial(player)) then if (getElementData(source,"lockeds") == false) then return else if (seat == 0) then cancelEvent() outputChatBox("This is not your vehicle!",player,0,255,255) end end end end end addEventHandler("onVehicleStartEnter",getRootElement(),inveh) function share(player,cmd) if (getVehicleOccupant(getPedOccupiedVehicle(player),0) == player) then setElementData(getPedOccupiedVehicle(player),"lockeds",false) setElementData(getPedOccupiedVehicle(player),"lock",false) outputChatBox("Vehicle is now shared with everyone!",player,0,255,255) else outputChatBox("You need to be the driver!",player,0,255,255) end end addCommandHandler("share",share) function ejectPlayer(player,cmd,eject) if (getVehicleOccupant(getPedOccupiedVehicle(player),0) == player) then removePlayerFromVehicle(getPlayerFromPartialName(eject)) outputChatBox(getPlayerName(player).." has removed you from the vehicle!",getPlayerFromPartialName(eject),0,255,255) else outputChatBox("You need to be the driver!",player,0,255,255) end end addCommandHandler("eject",ejectPlayer) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end Link to comment
Rataj Posted July 29, 2016 Share Posted July 29, 2016 If I got it, you just want suggestions to improve your resource, right? I think you should save your lock status into a database, so it'll stay after server restart. Also definitely add option to lock your vehicle from outside. But I'm not sure if my suggestions are good for you, since you didn't write what gamemode is this for. RPG? Freeroam? Link to comment
shaio Posted July 29, 2016 Author Share Posted July 29, 2016 first question (yes) second question (freeroam) I run my own freeroam/drift/rp/zombies gamemode server, its kinda just a bunch of shit piled on , but it did turn out pretty decent. This lock script to me just seems like a piece of mumbo jumbo. How would i make /share so u could share with a specific person, enable and disable it for that person and what not.. I also dont like how everytime a person enters a car, the data changes to their serial.. Link to comment
LabiVila Posted July 30, 2016 Share Posted July 30, 2016 Firstly, I think you should use tables and not elemnt datas since it'll mess things up (in my opinion at least) and tables are made for such things. So you can do something like this: local players = {shares = {}} now everytime you want someone to lock, you insert the player this way: players [player] = {} and everytime you want to share the table with someone, you write: for _,v in pairs (players) do table.insert (v.shares, sharedPlayer) end now when a player wants to get in the car, you can check it this way (if he's allowed) for _,v in pairs (players) do for _,a in pairs (v.shares) do if (a == specifiedPlayerWhoWantsToJoinTheCar) then --allow him end end end and by the way, don't you need a function to remove the player from `car share` ? Link to comment
shaio Posted July 31, 2016 Author Share Posted July 31, 2016 ill just check if the player is 'shared' with the same function, and if so, unshare them But how would i save the players serial to the tables..? Link to comment
LabiVila Posted July 31, 2016 Share Posted July 31, 2016 I used (would personally use) player element instead of serial, but if that's how you really want it: players = {} local currentSerial = getPlayerSerial (player) players [currentSerial] = {shares = {}, lockable = false / true and anything you want here} Link to comment
shaio Posted August 1, 2016 Author Share Posted August 1, 2016 Honestly, I have no fucking clue how to add this shit to my script . Link to comment
LabiVila Posted August 1, 2016 Share Posted August 1, 2016 Do not add this to your script, just start testing how this kind of tables work out. Then make a Lock System around this, not around getElementDatas, it should be far more efficient and better Link to comment
shaio Posted August 6, 2016 Author Share Posted August 6, 2016 How would I make the tables save to vehicle? Link to comment
shaio Posted August 6, 2016 Author Share Posted August 6, 2016 This is what I have.. local players = {shares = {}} addEventHandler("onPlayerJoin",getRootElement(),function() bindKey(source,"k","down","lock") end) addEventHandler("onResourceStart",getRootElement(),function() for _,plr in ipairs(getElementsByType("player")) do bindKey(plr,"k","down","lock") end end) function lockVehicle(player,cmd) local vehicle = getPedOccupiedVehicle(player) if isVehicleLocked(vehicle) then setVehicleLocked(vehicle,false) else setVehicleLocked(vehicle,true) players[player] = {} end end addCommandHandler("lock",lockVehicle) function shareLock(player,cmd,other) local serial = getPlayerSerial(getPlayerFromPartialName(other)) for _,v in pairs(players) do table.insert(v.shares,serial) end end addCommandHandler("allow",shareLock) addEventHandler("onVehicleStartEnter",getRootElement(),function(player,seat,jacked) for _,v in pairs(players) do for _,a in pairs(v.shares) do if (a == player) then return else cancelEvent() end end end end) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x",""):lower() or nil if name then for _,player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x",""):lower() if name_:find(name,1,true) then return player end end end end Link to comment
shaio Posted August 7, 2016 Author Share Posted August 7, 2016 could anyone help me save the tables to vehicle? Link to comment
LabiVila Posted August 8, 2016 Share Posted August 8, 2016 How do you want to save the tables to vehicle? Could you explain more? Link to comment
shaio Posted August 10, 2016 Author Share Posted August 10, 2016 I'm making the tables yes but the tables need to save to separate vehicles.. Link to comment
LabiVila Posted August 11, 2016 Share Posted August 11, 2016 You can use something like this: players [player] = {cars = {}} now you can insert cars and 'carLock' like this: table.insert (v.cars, {car, sharable = true / false }} Link to comment
shaio Posted August 13, 2016 Author Share Posted August 13, 2016 could someone script it out for me so i can get a better understanding? Link to comment
shaio Posted August 13, 2016 Author Share Posted August 13, 2016 Could u script a part of it out cuz I really don't understand.. Link to comment
LabiVila Posted August 13, 2016 Share Posted August 13, 2016 local players = {cars = {}, unlockedFor = {}} addCommandHandler ("vehUser", function (player) players [player] = {} end ) addCommandHandler ("addVehicle", function (player, _, car) for name, v in pairs (players) do if (name == player) then table.insert (v.cars, car) end ) addCommandHandler ("lockFor", function (player, _, otherPlayer) local otherPlayer = getPlayerFromName (otherPlayer) for name, v in pairs (players) do if (name == player) then table.insert (v.unlockedFor, otherPlayer) end end end ) It looks a lot like this. Now you can do the 'unlockCarFor' command, opposite of the one above. and when a player enters the car as passager, you can loop through v.unlockedFor, see if there's a name similiar to the one that wants to enter, if yes let him enter, if no then cancelEvent Link to comment
shaio Posted August 13, 2016 Author Share Posted August 13, 2016 im still hella confused 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