Jump to content

[Help] Failed to create a vehicle


TheBull

Recommended Posts

Posted

Helloo Guys.

I've made a script to creat a rhino for vip players only but it's not working dont know why ,and when i spawn the vehicle i can't enter the vehicle,here are my codes :

Client :

function scriptCreateTank ( commandName ) 
      local luckyBugger = getLocalPlayer()  
      local x, y, z = getElementPosition ( luckyBugger )  
      createVehicle ( 432, x + 7, y, z + 2 )  
end 
  
addCommandHandler ( "tank", scriptCreateTank ) 
addEvent("creatTank", true ) 
addEventHandler("creatTank", getRootElement(), scriptCreateTank )  

Server :

function creatVehicleCommand ( playerSource, commandName ) 
    local acc = getPlayerAccount (playerSource) 
    if acc and not isGuestAccount(acc) then 
    local accName = getAccountName (acc ) 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "VIP" ) ) then 
        local theTriggerer = getPlayerName ( playerSource ) 
        if commandName == "tank" then 
                triggerClientEvent (root,  "creatTank") 
            end 
        end 
    end 
end 
addCommandHandler ( "tank", creatVehicleCommand ) 

Posted

-- Server Side 
  
function creatVehicleCommand ( playerSource, commandName ) 
    local acc = getPlayerAccount (playerSource) 
    if acc and not isGuestAccount(acc) then 
    local accName = getAccountName (acc ) 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "VIP" ) ) then 
    triggerClientEvent (playerSource,  "creatTank",playerSource) 
        end 
    end 
end 
addCommandHandler ( "tank", creatVehicleCommand ) 

-- Client Side 
  
addEvent("creatTank", true ) 
addEventHandler("creatTank", root, 
function (    ) 
      local x, y, z = getElementPosition ( localPlayer ) 
      if ( isElement ( vehicle ) ) then destroyElement ( vehicle ) 
      vehicle = nil 
      vehicle = createVehicle ( 432, x + 7, y, z + 2 )  
             end 
     end 
 ) 
Posted

Vehicles created client-side are useless. You cant enter them, change colour etc. You must create them server-side in order to use them.

Posted
-- Server Side 
  
function creatVehicleCommand ( playerSource, commandName ) 
    local acc = getPlayerAccount (playerSource) 
    if acc and not isGuestAccount(acc) then 
    local accName = getAccountName (acc ) 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "VIP" ) ) then 
    triggerClientEvent (playerSource,  "creatTank",playerSource) 
        end 
    end 
end 
addCommandHandler ( "tank", creatVehicleCommand ) 

-- Client Side 
  
addEvent("creatTank", true ) 
addEventHandler("creatTank", root, 
function (    ) 
      local x, y, z = getElementPosition ( localPlayer ) 
      if ( isElement ( vehicle ) ) then destroyElement ( vehicle ) 
      vehicle = nil 
      vehicle = createVehicle ( 432, x + 7, y, z + 2 )  
             end 
     end 
 ) 

Not working.No errors appeared.

Posted

try this !

-- Server Side 
   
function creatVehicleCommand ( playerSource, commandName ) 
    local acc = getPlayerAccount (playerSource) 
    if acc and not isGuestAccount(acc) then 
    local accName = getAccountName (acc ) 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "VIP" ) ) then 
    local x, y, z = getElementPosition ( playerSource ) 
     if ( isElement ( vehicle ) ) then destroyElement ( vehicle ) 
      vehicle = nil 
      vehicle = createVehicle ( 432, x + 7, y, z + 2 ) 
              end 
        end 
    end 
end 
addCommandHandler ( "tank", creatVehicleCommand ) 
Posted

Server:

veh = {} 
  
addCommandHandler("tank", 
function(player) 
    local account = getPlayerAccount(player) 
    if account and not isGuestAccount(account) then 
        local accountName = getAccountName(account) 
        if isObjectInACLGroup("user."..accountName, aclGetGroup("VIP")) then  
            if isElement(veh[player]) then 
                destroyElement(veh[player]) 
                veh[player] = nil 
            end 
            local x, y, z = getElementPosition(player) 
            veh[player] = createVehicle(432, x+7, y, z+2) 
        end 
    end 
end) 

Don't forget to remove the vehicle when explode or player quit from the server.

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