Pedro001 Posted August 11, 2018 Share Posted August 11, 2018 Hi people! me again Guy I'm completley new to it, so I know nothing about scripting. But I need a simple resource, a simple script which by using a command, ex(/veh421) a particular player will be able to spawn a particular vehicle that won't be in the F1 menu list; It is supposed to be a private vehicle but not only the player will be able to drive it. I just need that this player is the only one who can spawn it. I found a resource online but it allowes only the ones in the ACL group to get in the car, But that's not what I need. In resume, I need a resource that allows a particular player to spawn a particular vehicle, and this vehicle can be used by other players. Thank you very much buys. Link to comment
WorthlessCynomys Posted August 11, 2018 Share Posted August 11, 2018 (edited) How do you want to specify the player who can get it and drive it? Do you want to do it by name, serial code or do you want it like players in a certain group are allowed to do that? You can check if the player is the one you want by serial code. I assume that if you want to restrict the use of this function for a specific player, you can get the serial code belonging to it's PC. You can do it based on player name, but since other players can change their names any time, it wouldn't really be restricted to a player, but to a name instead. You can do it based on ACL groups, adding only the specified player to that group, but admins can add objects to ACL groups so that wouldn't be so restricted neither. You can also do it based on teams, but there's the same problem as with ACL groups. The best option (if you want it to be useable by only one specific player) is the serial based. On the call of this command you comapre the serial of the sourcePlayer with the serial of the player who can spawn the car. If it's a match, spawn the car. If it isn't output a message or do something. Maybe do nothing. Edited August 11, 2018 by WorthlessCynomys Additional content Link to comment
Pedro001 Posted August 11, 2018 Author Share Posted August 11, 2018 39 minutes ago, WorthlessCynomys said: How do you want to specify the player who can get it and drive it? Do you want to do it by name, serial code or do you want it like players in a certain group are allowed to do that? You can check if the player is the one you want by serial code. I assume that if you want to restrict the use of this function for a specific player, you can get the serial code belonging to it's PC. You can do it based on player name, but since other players can change their names any time, it wouldn't really be restricted to a player, but to a name instead. You can do it based on ACL groups, adding only the specified player to that group, but admins can add objects to ACL groups so that wouldn't be so restricted neither. You can also do it based on teams, but there's the same problem as with ACL groups. The best option (if you want it to be useable by only one specific player) is the serial based. On the call of this command you comapre the serial of the sourcePlayer with the serial of the player who can spawn the car. If it's a match, spawn the car. If it isn't output a message or do something. Maybe do nothing. Yeah! Doing it by comparing serial code would be excelent! But like I said, I know nothing about scripting I have no Idea of how to do that. Link to comment
WorthlessCynomys Posted August 11, 2018 Share Posted August 11, 2018 Well... You should start off by creating the meta.xml file (you can find it's documentation on wiki) and the script files in a resource (basically a folder in the resources folder of your server). After that, start a function, like: function functionName () end and then use the already provided functions for this matter getPlayerSerial() getElementPosition() createVehicle() You can use if statements to compare and decide: if (condition) then -- Spawn the vehicle end Link to comment
Pedro001 Posted August 12, 2018 Author Share Posted August 12, 2018 16 minutes ago, WorthlessCynomys said: Well... You should start off by creating the meta.xml file (you can find it's documentation on wiki) and the script files in a resource (basically a folder in the resources folder of your server). After that, start a function, like: function functionName () end and then use the already provided functions for this matter getPlayerSerial() getElementPosition() createVehicle() You can use if statements to compare and decide: if (condition) then -- Spawn the vehicle end ...I won't lie to you man, I didn't understand a single word of that, but I promise I'll do my best to learn it. Link to comment
Keiichi1 Posted August 12, 2018 Share Posted August 12, 2018 I know if I do this for you, you won't learn anything but... I want to help newbies. local allowedSerials = { ["SomeSerial"] = true, -- Change it to the players serial you want to grant access to /veh command --["SomeSerial2"] = true } addCommandHandler("veh", function(thePlayer, cmd, vehid) -- Adding 'veh' command handler if tonumber(vehid) then -- Check if the 'vehid' arg. is a number if allowedSerials[getPlayerSerial(thePlayer)] then -- Check if the player using the command have his/her serial in the table local vehname = getVehicleNameFromModel(tonumber(vehid)) -- Getting vehicle name if vehname ~= "" then -- If vehicle name is not an empty string local x, y, z = getElementPosition(thePlayer) -- Getting his/her positions local veh = createVehicle(tonumber(vehid), x, y+3, z) -- Creating the vehicle near the player if veh then -- If the vehicle created successfully outputChatBox("Created vehicle: "..vehname, thePlayer) -- Output the created vehicle's name end else outputChatBox("Please enter a valid vehicle model ID.", thePlayer) -- If the specified ID is not valid end else outputChatBox("You don't have access to this command.", thePlayer) -- If the players serial is not in the table end else outputChatBox("[SYNTAX]: /"..cmd.." [Model ID]", thePlayer) -- If the 'vehid' arg. is not specified or not a number end end) I wrote some comments, read it, hope you understand how it works! 1 Link to comment
Pedro001 Posted August 13, 2018 Author Share Posted August 13, 2018 On 12/08/2018 at 15:30, Keiichi1 said: I know if I do this for you, you won't learn anything but... I want to help newbies. local allowedSerials = { ["SomeSerial"] = true, -- Change it to the players serial you want to grant access to /veh command --["SomeSerial2"] = true } addCommandHandler("veh", function(thePlayer, cmd, vehid) -- Adding 'veh' command handler if tonumber(vehid) then -- Check if the 'vehid' arg. is a number if allowedSerials[getPlayerSerial(thePlayer)] then -- Check if the player using the command have his/her serial in the table local vehname = getVehicleNameFromModel(tonumber(vehid)) -- Getting vehicle name if vehname ~= "" then -- If vehicle name is not an empty string local x, y, z = getElementPosition(thePlayer) -- Getting his/her positions local veh = createVehicle(tonumber(vehid), x, y+3, z) -- Creating the vehicle near the player if veh then -- If the vehicle created successfully outputChatBox("Created vehicle: "..vehname, thePlayer) -- Output the created vehicle's name end else outputChatBox("Please enter a valid vehicle model ID.", thePlayer) -- If the specified ID is not valid end else outputChatBox("You don't have access to this command.", thePlayer) -- If the players serial is not in the table end else outputChatBox("[SYNTAX]: /"..cmd.." [Model ID]", thePlayer) -- If the 'vehid' arg. is not specified or not a number end end) I wrote some comments, read it, hope you understand how it works! Yey man! You helped me a lot!, I already get the logic behind it, I'm just not familiar with the terms, and also, I needed the code to give the player access to a specific vehicle, and aparently with this code the player can spawn any vehicle he wants. I'll keep on trying to learn it, But if you want to help me out with it, I won't refuse hehe. Thank you very much! Link to comment
WorthlessCynomys Posted August 13, 2018 Share Posted August 13, 2018 9 minutes ago, Pedro001 said: Yey man! You helped me a lot!, I already get the logic behind it, I'm just not familiar with the terms, and also, I needed the code to give the player access to a specific vehicle, and aparently with this code the player can spawn any vehicle he wants. I'll keep on trying to learn it, But if you want to help me out with it, I won't refuse hehe. Thank you very much! I'm not the one who helped, but this community is about this. Feel completely free to ask about anything realted to scripting! 1 Link to comment
Pedro001 Posted August 13, 2018 Author Share Posted August 13, 2018 10 minutes ago, WorthlessCynomys said: I'm not the one who helped, but this community is about this. Feel completely free to ask about anything realted to scripting! Thank you very much! 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