Jump to content

[REQ]help with carlocking recource


gtrg

Recommended Posts

hey ive tried to make a carlocking recource that:

-locks on player accounts

-adds color and upgrades

-easy to add vehicles

i've made it quite far i think myself cause im only 14 yet

so here's my code

model       = {}  
x       = {} 
y       = {} 
z       = {} 
rx      = {} 
ry      = {} 
rz      = {} 
numberplate     = {} 
upgrades    = {} 
color       = {} 
paintjob    = {} 
owner       = {} 
temp            = {} 
vehicle     = {} 
  
  
  
  
function loadup(startedRecource) 
    vehicles = xmlLoadFile ( "vehicles.xml" ) 
    count = xmlNodeGetChildren(vehicles) 
  
        for i=1,#count do        
        local vehicle = xmlFindChild ( vehicles, "vehicle", i-1 ) 
        local attributes = xmlNodeGetAttributes ( vehicle ) 
        for name,value in pairs ( attributes ) do 
                temp["" .. name .. ""] = value 
        end 
          
        x[i]         = temp["posX"] 
        y[i]         = temp["posY"] 
        z[i]         = temp["posZ"] 
        rx[i]        = temp["rotX"] 
        ry[i]        = temp["rotY"] 
        rz[i]        = temp["rotZ"] 
        numberplate[i]   = temp["plate"] 
        upgrades[i]      = temp["upgrades"] 
        color[i]     = temp["color"] 
        paintjob[i]      = temp["paintjob"] 
        owner[i]     = temp["id"] 
        model[i]     = temp["model"] 
  
        vehicle = createVehicle ( model[i], x[i], y[i], z[i], rx[i], ry[i], rz[i], numberplate[i]) 
        addVehicleUpgrade ( vehicle, 1010 ) 
        setVehicleColor ( vehicle, 0, 0, 0, 0) 
  
end 
    xmlUnloadFile ( vehicles ) 
end 
  
function checkowner (player,seat,jacked)  
local account = getPlayerAccount( sourcePlayer) 
local accountName = getAccountName(account) 
if owner[i] == accountName and seat == 0 then  
outputChatBox ( "You cannot drive this vehicle as it belongs to: "..tostring(owner), player, 200, 0, 0 )  
cancelEvent()  
end  
end  
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), loadup ) 
addEventHandler ( "onVehicleStartEnter", getRootElement(), checkowner) 

and this is in the vehicles.xml

    "admingtrg" paintjob="3" model="411" plate="admingtrg" interior="0" dimension="0" color="0,0,0,0" posX="1075.5999755859" posY="1230.1999511719" posZ="10.60000038147" rotX="0" rotY="0" rotZ="0" upgrades="1010">

and this are my errors when someone is trying to enter the car, they succeed always

[2012-01-31 10:19:42] WARNING: [gameplay]\carlocking\server.lua:52: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil]

[2012-01-31 10:19:42] WARNING: [gameplay]\carlocking\server.lua:53: Bad argument @ 'getAccountName' [Expected account at argument 1, got boolean]

if someone would help me that would be great because this recource would be really helpful for alot of people

greetz

Gtrg

Link to comment
model       = {} 
x       = {} 
y       = {} 
z       = {} 
rx      = {} 
ry      = {} 
rz      = {} 
numberplate     = {} 
upgrades    = {} 
color       = {} 
paintjob    = {} 
owner       = {} 
temp            = {} 
vehicle     = {} 
  
  
  
  
function loadup(startedRecource) 
    vehicles = xmlLoadFile ( "vehicles.xml" ) 
    count = xmlNodeGetChildren(vehicles) 
  
        for i=1,#count do       
        local vehicle = xmlFindChild ( vehicles, "vehicle", i-1 ) 
        local attributes = xmlNodeGetAttributes ( vehicle ) 
        for name,value in pairs ( attributes ) do 
                temp["" .. name .. ""] = value 
        end 
          
        x[i]         = temp["posX"] 
        y[i]         = temp["posY"] 
        z[i]         = temp["posZ"] 
        rx[i]        = temp["rotX"] 
        ry[i]        = temp["rotY"] 
        rz[i]        = temp["rotZ"] 
        numberplate[i]   = temp["plate"] 
        upgrades[i]      = temp["upgrades"] 
        color[i]     = temp["color"] 
        paintjob[i]      = temp["paintjob"] 
        owner[i]     = temp["id"] 
        model[i]     = temp["model"] 
  
        vehicle = createVehicle ( model[i], x[i], y[i], z[i], rx[i], ry[i], rz[i], numberplate[i]) 
        addVehicleUpgrade ( vehicle, 1010 ) 
        setVehicleColor ( vehicle, 0, 0, 0, 0) 
  
end 
    xmlUnloadFile ( vehicles ) 
end 
  
function checkowner (player,seat,jacked) 
local account = getPlayerAccount( player) 
local accountName = getAccountName(account) 
if owner[i] == accountName and seat == 0 then 
outputChatBox ( "You cannot drive this vehicle as it belongs to: "..tostring(owner), player, 200, 0, 0 ) 
cancelEvent() 
end 
end 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), loadup ) 
addEventHandler ( "onVehicleStartEnter", getRootElement(), checkowner) 

Link to comment
model       = {} 
x       = {} 
y       = {} 
z       = {} 
rx      = {} 
ry      = {} 
rz      = {} 
numberplate     = {} 
upgrades    = {} 
color       = {} 
paintjob    = {} 
owner       = {} 
temp            = {} 
vehicle     = {} 
  
  
  
  
function loadup(startedRecource) 
    vehicles = xmlLoadFile ( "vehicles.xml" ) 
    count = xmlNodeGetChildren(vehicles) 
  
        for i=1,#count do       
        local vehicle = xmlFindChild ( vehicles, "vehicle", i-1 ) 
        local attributes = xmlNodeGetAttributes ( vehicle ) 
        for name,value in pairs ( attributes ) do 
                temp["" .. name .. ""] = value 
        end 
          
        x[i]         = temp["posX"] 
        y[i]         = temp["posY"] 
        z[i]         = temp["posZ"] 
        rx[i]        = temp["rotX"] 
        ry[i]        = temp["rotY"] 
        rz[i]        = temp["rotZ"] 
        numberplate[i]   = temp["plate"] 
        upgrades[i]      = temp["upgrades"] 
        color[i]     = temp["color"] 
        paintjob[i]      = temp["paintjob"] 
        owner[i]     = temp["id"] 
        model[i]     = temp["model"] 
  
        vehicle = createVehicle ( model[i], x[i], y[i], z[i], rx[i], ry[i], rz[i], numberplate[i]) 
        addVehicleUpgrade ( vehicle, 1010 ) 
        setVehicleColor ( vehicle, 0, 0, 0, 0) 
  
end 
    xmlUnloadFile ( vehicles ) 
end 
  
function checkowner (player,seat,jacked) 
local account = getPlayerAccount( player) 
local accountName = getAccountName(account) 
if owner[i] ~= accountName and seat == 0 then 
outputChatBox ( "You cannot drive this vehicle as it belongs to: "..tostring(owner[i]), player, 200, 0, 0 ) 
cancelEvent() 
end 
end 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), loadup ) 
addEventHandler ( "onVehicleStartEnter", getRootElement(), checkowner) 

Link to comment

THANK U

your version did only need one thing more

i forgot it wile i was re-making it after a big faillure

in the loadup there just needed to be a variable that pinpointed at owner

done that now it works comepletely fine

thanks for u help

Link to comment

hey JR10 and how i can change for be uused only by admins?

somethingl like this?

  
function checkowner (player,seat,jacked) 
local account = getPlayerAccount( player) 
if isObjectInACLGroup( 'user.'..getAccountName( player ), aclGetGroup( 'Admin' ))  and seat == 0 then 
outputChatBox ( "You cannot drive this vehicle as it belongs to Admins ", player, 200, 0, 0 ) 
cancelEvent() 
end 
end 
  

Link to comment
function checkowner (player,seat,jacked) 
    local account = getPlayerAccount( player) 
    if (seat == 0 and not isObjectInACLGroup( 'user.'..getAccountName( account ), aclGetGroup( 'Admin' ))) then 
        outputChatBox ( "You cannot drive this vehicle as it belongs to Admins ", player, 200, 0, 0 ) 
        cancelEvent() 
    end 
end 

Link to comment
function checkowner (player,seat,jacked) 
    local account = getPlayerAccount( player) 
    if (seat == 0 and not isObjectInACLGroup( 'user.'..getAccountName( account ), aclGetGroup( 'Admin' ))) then 
        outputChatBox ( "You cannot drive this vehicle as it belongs to Admins ", player, 200, 0, 0 ) 
        cancelEvent() 
    end 
end 

'player' in getAccountName instead of 'account'.

Link to comment
  
model       = {} 
x       = {} 
y       = {} 
z       = {} 
rx      = {} 
ry      = {} 
rz      = {} 
numberplate     = {} 
  
paintjob    = {} 
  
temp            = {} 
vehicle     = {} 
  
function loadup(startedRecource) 
    vehicles = xmlLoadFile ( "vehicles.xml" ) 
    count = xmlNodeGetChildren(vehicles) 
  
        for i=1,#count do       
        local vehicle = xmlFindChild ( vehicles, "vehicle", i-1 ) 
        local attributes = xmlNodeGetAttributes ( vehicle ) 
        for name,value in pairs ( attributes ) do 
                temp["" .. name .. ""] = value 
        end 
          
        x[i]         = temp["posX"] 
        y[i]         = temp["posY"] 
        z[i]         = temp["posZ"] 
        rx[i]        = temp["rotX"] 
        ry[i]        = temp["rotY"] 
        rz[i]        = temp["rotZ"] 
        numberplate[i]   = temp["plate"] 
  
        paintjob[i]      = temp["paintjob"] 
  
        model[i]     = temp["model"] 
  
        vehicle = createVehicle ( model[i], x[i], y[i], z[i], rx[i], ry[i], rz[i], numberplate[i]) 
setVehicleHeadLightColor (vehicle, 0, 0, 255) 
setVehicleColor ( vehicle, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) 
end 
    xmlUnloadFile ( vehicles ) 
end 
  
function checkowner (player,seat,jacked) 
    local account = getPlayerAccount( player) 
    if (seat == 0 and not isObjectInACLGroup( 'user.'..getAccountName( account ), aclGetGroup( 'Admin' ))) then 
        outputChatBox ( "Car designed for admins", player, 200, 0, 0 ) 
        cancelEvent() 
    end 
end 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), loadup ) 
addEventHandler ( "onVehicleStartEnter", getRootElement(), checkowner) 
  

just i remove some lines

vehicle.xml

  

    "3" model="497" plate="Yakuza" interior="0" dimension="0"  posX="830.70001220703" posY="-2598.3000488281" posZ="15.5" rotX="0" rotY="0" rotZ="0">
  

Link to comment

Look, leetme explain better

i have a zombie server. this gamemode have a map file with cars arround all San andreas.

I have a base for Admins and i want make this private cars only for us.

But when i active this resource. Nobody can enter to all cars in san andreas

not only to car created in this scripts,

and that map file and this scripts are in diferents resources

i mean the map file with cars arround san andreas are in resource biohazard

and this scripts its called privatecars

i dont know if i explain.

Link to comment
  
model       = {} 
x       = {} 
y       = {} 
z       = {} 
rx      = {} 
ry      = {} 
rz      = {} 
numberplate     = {} 
  
paintjob    = {} 
  
temp            = {} 
vehicle     = {} 
  
function loadup(startedRecource) 
    vehicles = xmlLoadFile ( "vehicles.xml" ) 
    count = xmlNodeGetChildren(vehicles) 
  
        for i=1,#count do       
        local vehicle = xmlFindChild ( vehicles, "vehicle", i-1 ) 
        local attributes = xmlNodeGetAttributes ( vehicle ) 
        for name,value in pairs ( attributes ) do 
                temp["" .. name .. ""] = value 
        end 
          
        x[i]         = temp["posX"] 
        y[i]         = temp["posY"] 
        z[i]         = temp["posZ"] 
        rx[i]        = temp["rotX"] 
        ry[i]        = temp["rotY"] 
        rz[i]        = temp["rotZ"] 
        numberplate[i]   = temp["plate"] 
  
        paintjob[i]      = temp["paintjob"] 
  
        model[i]     = temp["model"] 
  
        vehicle = createVehicle ( model[i], x[i], y[i], z[i], rx[i], ry[i], rz[i], numberplate[i]) 
setVehicleHeadLightColor (vehicle, 0, 0, 255) 
setVehicleColor ( vehicle, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) 
end 
    xmlUnloadFile ( vehicles ) 
end 
  
function checkowner (player,seat,jacked) 
    local account = getPlayerAccount( player) 
    if (seat == 0 and not isObjectInACLGroup( 'user.'..getAccountName( account ), aclGetGroup( 'Admin' ))) then 
        outputChatBox ( "Car designed for admins", player, 200, 0, 0 ) 
        cancelEvent() 
    end 
end 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), loadup ) 
addEventHandler ( "onVehicleStartEnter", resourceRoot, checkowner) 
  

Not sure if this is what you mean.

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