Jump to content

(50P SpawnScript Collum) --- Locking cars to 2 classes


jonas13362

Recommended Posts

Hello ,

I would like to make a new collum named 'Jobs'

I tried to make it already but it isnt working for some reason

Im getting bad argument @ 'setElementData" [expected element at argument 1, got nil]

here is the script line :

  
setElementData(thePlayer,"Job","Job Name") 
  

Edited by Guest
Link to comment

solved , ok another question how to lock a car to this elementdata?

  
  
local vehicle = createVehicle(506, 2100.2697, 1397.4947, 10.3, 0, 0, 0) -- Create the vehicle 
setElementData(vehicle, "HLS", true, false) -- Give it element data in 'Chief' and make its value a boolean 'true' 
  
addEventHandler("onVehicleStartEnter", root, 
    function(thePlayer, seat, jacked, door) 
        local vehicleOwner = getElementData(source, "HLS") -- Get the vehicle's element data on 'Chief' 
        local gangGroup = getElementData( client, "HLS", skin.name ) -- Get the entering player's element data on 'Chief' 
        if (not vehicleOwner) then return end -- If the vehicle doesn't have such data, then cancel 
        if (gangGroup ~= vehicleOwner) then -- If the entering player's data doesn't match the vehicle data, continue 
            outputChatBox("This car is locked and belongs to the following class: Admins", thePlayer, 245, 20, 20, false) -- Display a warning 
            cancelEvent() -- Prevent the player from entering the vehicle 
        end 
    end 
) 

I tried this already but it doesnt work (i found this script in a other forum since i didnt know how to get it work ^)

Link to comment

It would be better to create vehciles in your map file. From there you can easily set their data to certain values. Let's say the data name for vehicles is "owner", you can then set it to one of the values possible for "job" data name. Let's say you have a "Pizzaboy" job, and you've set it to a player. Now you have to create a vehicle with the "owner" data being "Pizzaboy" too, so they can use the vehicle. The script to allow/disallow certain players to use a vehicle is fairly simple. Things you're going to need:

The "onVehicleStartEnter" - so you know when a player tries to enter a vehicle,

The getElementData() function - so you can compare the player's "job" with the vehicle's "owner"

The cancelEvent() function - so you can disallow the player to use a vehicle if the data don't match.

Link to comment
He's not asking to lock them as lock in the doors, I think he means that it doesn't let you drive it if you ain't of that class.

Exactly what i wanted

It would be better to create vehciles in your map file. From there you can easily set their data to certain values. Let's say the data name for vehicles is "owner", you can then set it to one of the values possible for "job" data name. Let's say you have a "Pizzaboy" job, and you've set it to a player. Now you have to create a vehicle with the "owner" data being "Pizzaboy" too, so they can use the vehicle. The script to allow/disallow certain players to use a vehicle is fairly simple. Things you're going to need:

The "onVehicleStartEnter" - so you know when a player tries to enter a vehicle,

The getElementData() function - so you can compare the player's "job" with the vehicle's "owner"

The cancelEvent() function - so you can disallow the player to use a vehicle if the data don't match.

Hhhm was confused a sec , so the functions are onVehicleStartEnter and GetElementData() and cancelEvent()

Will try to make it tongiht

oh with map editor dont rlly get a thing , dont we need to create the vehicle in the script and not via map editor?

Link to comment

You don't have to use the map editor at all. Just add the cars in your map file using any text editor. That makes the mapmanager resource responsible of creating all the vehicles and stuff, so you can concentrate on the script itself. It makes things just so much easier than using createVehicle() all the time.

Link to comment
line 9:
local gangGroup = getElementData( client, "HLS", skin.name ) 

What's skin.name supposed to be?

Also, use thePlayer instead of "client"

local gangGroup = getElementData( thePlayer, "HLS" ) 

This script didnt worked

You don't have to use the map editor at all. Just add the cars in your map file using any text editor. That makes the mapmanager resource responsible of creating all the vehicles and stuff, so you can concentrate on the script itself. It makes things just so much easier than using createVehicle() all the time.

I meant that i dont know how to 'combine' it like u just have to place a car and then u have to locate that car or?

BTW i want only 1 vehicle locked to 'HLS' and not all the vehicles

with other words u just locked 1 car wich is created not the whole ID

Link to comment
local vehicle = createVehicle(506, 2100.2697, 1397.4947, 10.3, 0, 0, 0) 
setElementData(vehicle, "HLS", "groupname") 
  
addEventHandler("onVehicleStartEnter", root, 
    function(thePlayer, seat, jacked, door) 
        local vehicleOwner = getElementData(source, "HLS") 
        local gangGroup = getElementData(thePlayer, "HLS") 
        if (not vehicleOwner) then return end 
        if (gangGroup ~= vehicleOwner) then 
            outputChatBox("This car is locked and belongs to the following class: Admins", thePlayer, 245, 20, 20, false) 
            cancelEvent() 
        end 
    end 
) 

Replace the groupname on line 2 with the name of the group.

Link to comment

Oh thank you ,

By the way i got 1 more last question ;

I would like to lock a class actualy

Here is an example :

I added a team 'Squads' , after that i added FBI and SWAT

I would like to lock only FBI to a ACL and SWAT to a other ACL so FBI members cant spawn SWAT i tought this should work but it isnt working ;

            local classACL = aclGetGroup( skin.name ); 
            local plrAccount = getPlayerAccount( client ); 
            if ( classACL ) then 
                if ( not isGuestAccount( plrAccount ) ) and ( not isObjectInACLGroup( "user." .. getAccountName( plrAccount ), classACL ) ) then 
                    outputChatBox( "You are not member of this team/gang. Choose different team!", client, 200, 50, 50 ); 
                    requestMenu( client ); 
                    return; 
                elseif isGuestAccount( plrAccount ) then 
                    outputChatBox( "If you are member of \"" .. skin.name .. "\" then please log in before you proceed.", client, 200, 50, 50 ); 
                    requestMenu( client ); 
                    return; 
                end 
            end 

(this i on line 21 at main_s.lua if u need the whole file tell me then i post it here , skin.name is difined as :

if spawned then

setElementData( client, "Team", class.name )

setElementData( client, "Job", skin.name )

Link to comment
local vehicle = createVehicle(506, 2100.2697, 1397.4947, 10.3, 0, 0, 0) 
setElementData(vehicle, "HLS", "groupname") 
  
addEventHandler("onVehicleStartEnter", root, 
    function(thePlayer, seat, jacked, door) 
        local vehicleOwner = getElementData(source, "HLS") 
        local gangGroup = getElementData(thePlayer, "HLS") 
        if (not vehicleOwner) then return end 
        if (gangGroup ~= vehicleOwner) then 
            outputChatBox("This car is locked and belongs to the following class: Admins", thePlayer, 245, 20, 20, false) 
            cancelEvent() 
        end 
    end 
) 

Replace the groupname on line 2 with the name of the group.

Am i also able to lock it to 2 classes?

I tried to use 2 times setElementData(vehicle, "HLS", "SWAT HQ")

And then again setElementData(vehicle, "HLS", "SWAT Member")

With 1 element it works only

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