Jump to content

Private car system.


Pedro001

Recommended Posts

Hi people! :D

me again 9_9:$

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

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 by WorthlessCynomys
Additional content
Link to comment
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 :crybaby:I have no Idea of how to do that. 

Link to comment

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
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

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!

  • Like 1
Link to comment
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!  9_9^_^

Link to comment
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!  9_9^_^

I'm not the one who helped, but this community is about this. Feel completely free to ask about anything realted to scripting! 

  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...