Jump to content

Only staff get some vehicles


//_Dragon

Recommended Posts

I make this but doesnt work :| i need to make it in fr_server.lua.

addEvent("buyHunter",true)  
addEventHandler("buyHunter",root,  
function() 
   if ( getPlayerMoney (source) >= 25000 ) then 
    takePlayerMoney(source, 25000) 
    vehicle = createVehicle(Hunter, vx, vy, vz, 0, 0, vrot) 
else 
outputChatBox('You successfully buy Hunter', source, 255, 0, 0 ) 
end 
end) 

Link to comment

No need to keep double-posting all the time, people will help you when they have time.

The reason it's not working is obvious, the event is already handled. This is the entire function;

function giveMeVehicles(vehicles) 
    if type(vehicles) == 'number' then 
        vehicles = { vehicles } 
    end 
    local px, py, pz, prot 
    local radius = 3 
    local playerVehicle = getPedOccupiedVehicle(source) 
    if playerVehicle and isElement(playerVehicle) then 
        px, py, pz = getElementPosition(playerVehicle) 
        prot, prot, prot = getVehicleRotation(playerVehicle) 
    else 
        px, py, pz = getElementPosition(source) 
        prot = getPedRotation(source) 
    end 
    local offsetRot = math.rad(prot) 
    local vx = px + radius * math.cos(offsetRot) 
    local vy = py + radius * math.sin(offsetRot) 
    local vz = pz + 2 
    local vrot = prot 
    local vehicleList = g_PlayerData[source].vehicles 
    local vehicle 
    if ( not vehicles ) then 
        return 
    end 
    for i,vehID in ipairs(vehicles) do 
        if i > getOption('vehicles.maxperplayer') then 
            break 
        end 
        if vehID < 400 or vehID > 611 then 
            errMsg(vehID ..' is incorrect vehicle model', source) 
        elseif not table.find(getOption('vehicles.disallowed'), vehID) then 
            if #vehicleList >= getOption('vehicles.maxperplayer') then 
                unloadVehicle(vehicleList[1]) 
            end 
        --///////// This was added 
        if(vehID == 520)  then 
            if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) then 
                vehicle = createVehicle(vehID, vx, vy, vz, 0, 0, vrot) 
            else 
                outputChatBox("You're not allowed to spawn this vehicle!", source, 187, 0, 0, true) 
            end 
        else 
            vehicle = createVehicle(vehID, vx, vy, vz, 0, 0, vrot) 
        end 
        --///////// 
        if (not isElement(vehicle)) then return end 
            setElementInterior(vehicle, getElementInterior(source)) 
            setElementDimension(vehicle, getElementDimension(source)) 
            table.insert(vehicleList, vehicle) 
            g_VehicleData[vehicle] = { creator = source, timers = {} } 
            if vehID == 464 then 
                warpPedIntoVehicle(source, vehicle) 
            elseif not g_Trailers[vehID] then 
                if getOption('vehicles.idleexplode') then 
                    g_VehicleData[vehicle].timers.fire = setTimer(commitArsonOnVehicle, getOption('vehicles.maxidletime'), 1, vehicle) 
                end 
                g_VehicleData[vehicle].timers.destroy = setTimer(unloadVehicle, getOption('vehicles.maxidletime') + (getOption('vehicles.idleexplode') and 10000 or 0), 1, vehicle) 
            end 
            vx = vx + 4 
            vz = vz + 4 
        else 
            errMsg(getVehicleNameFromModel(vehID):gsub('y$', 'ie') .. 's are not allowed', source) 
        end 
    end 
end 

As you can see, the function already exists - this is triggered whenever someone tries to spawn a vehicle via the F1 menu. So all you need to do is edit this code which I gave you.

else -- If the player does NOT have permission, output a message 
    outputChatBox("You're not allowed to spawn this vehicle!", source, 187, 0, 0, true) 
end 

This message will be shown for players that do not have the permission, so you already have the general behaviour needed. All you need to do is to make it so it takes away their money.

Another thing you did wrong is the variable Hunter. You can't just expect MTA to magically know what that variable should contain - you need to actually define it first. But since we already know the ID of the Hunter(520) we don't need to define a variable.

All in all, it would look like this;

else 
    if(getPlayerMoney(source) >= 25000) then 
        takePlayerMoney(source, 25000) 
        vehicle = createVehicle(520, vx, vy, vz, 0, 0, vrot) 
    else 
        outputChatBox("You can't afford this vehicle! ($25 000)", source, 187, 0, 0, true) 
    end 
end 

As you can see it's a really easy solution, and you'd probably have been able to figure it out if you read what I wrote thoroughly as well as follow examples on the MTA Wiki. If you don't know how to structure if statements properly, then you can search on google for information instead of rushing back here to bump your thread.

If you can't take the time to try and help yourself, don't expect us to help you. You can't always expect to get everything served on a silver platter. :roll:

Link to comment

Seriously I'm starting to believe you're just exploiting the friendly helpful community to script for you on scripts that you haven't actually wrote yourself — you have no Lua knowledge whatsoever as it appears to me. Please, consult the actual owners of the scripts you use.

Link to comment

It wasn't a little bug, it made no sense. It's evident you just copy and pasted from the wiki hoping it would somehow magically work.

It's possible I missed something, or you broke it - if you can post the function that would be helpful.

Also, I asked you to stop double-posting all the time, you have the ability to edit your reply. Use that instead. :shock:

Link to comment

I'm not a good scripter , Oly i'm still 39%

Anyway this what i do

if vehID == 520 or vehID == 432 then  
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) 
    then 
        vehicle = createVehicle(vehID, vx, vy, vz, 0, 0, vrot) 
    else 
        outputChatBox("You're not allowed to spawn this vehicle", source, 255, 0, 0, true) 
    end 
        else 
    if(getPlayerMoney(source) >= 25000) then 
        takePlayerMoney(source, 25000) 
        vehicle = createVehicle(425, vx, vy, vz, 0, 0, vrot) 
    else 
        outputChatBox("You dont have enought money (25000$)", source, 255, 0, 0, true) 
    end 
end 

Link to comment

You have if scopes mixed up.

if vehID == 520 or vehID == 432 then -- If you're looking for Hunter, I believe it is 425, not 432. 
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Console")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("SuperModerator")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Moderator")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Warden")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Girl")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Vip")) 
  then 
    vehicle = createVehicle(vehID, vx, vy, vz, 0, 0, vrot) 
  else 
-- outputChatBox("You're not allowed to spawn this vehicle", source, 255, 0, 0, true)                     -- these three lines should be removed 
-- end              -- these three lines should be removed (actually, it is moved to the end of the code) 
-- else             -- these three lines should be removed 
    if(getPlayerMoney(source) >= 25000) then 
      takePlayerMoney(source, 25000) 
      vehicle = createVehicle(vehID, vx, vy, vz, 0, 0, vrot) 
    else 
      outputChatBox("You dont have enought money ($25,000)", source, 255, 0, 0, true) 
      return false -- break the function here so freeroam doesn't try to do anything else with the vehicle since it doesn't get created anyway 
    end 
  end 
end --and one more end (as if it was moved from line 13 to here) 

Link to comment

No vehicle wanna get from F1 Only vehID's 520 & 432 & 425

I think the problem is in aclGetGroup("Everyone")) should be added ?

if vehID == 520 or vehID == 432 or vehID == 425 then 
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Console")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("SuperModerator")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Moderator")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Warden")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Girl")) 
  or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Vip")) 
  then 
    vehicle = createVehicle(vehID, vx, vy, vz, 0, 0, vrot) 
  else 
    if(getPlayerMoney(source) >= 25000) then 
      takePlayerMoney(source, 25000) 
      vehicle = createVehicle(425, vx, vy, vz, 0, 0, vrot) 
    else 
      outputChatBox("You dont have enought money ($25,000)", source, 255, 0, 0, true) 
      return false  
    end 
  end 
end 

Link to comment

Sigh... I could've guessed that's what you did wrong. All you did was copy and paste it in there, I told you to replace it...

You don't need to check if they belong to the group Everyone. You're already checking whether or not they are in a specific group - if all of them fail, you can just assume that they're in the group Everyone - this is what else does.

if vehID == 520 or vehID == 432 or vehID == 425 then 
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Console")) 
    or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) 
    or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("SuperModerator")) 
    or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Moderator")) 
    or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Warden")) 
    or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Girl")) 
    or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Vip")) 
    then 
        vehicle = createVehicle(vehID, vx, vy, vz, 0, 0, vrot) 
    else 
        if(getPlayerMoney(source) >= 25000) then 
            takePlayerMoney(source, 25000) 
            vehicle = createVehicle(vehID, vx, vy, vz, 0, 0, vrot) 
        else 
            outputChatBox("You dont have enought money ($25,000)", source, 255, 0, 0, true) 
        end 
    end 
end 

From what I can tell that should work, use debugscript to see if it reports any errors. It's possible some other if statements may have broken or whatnot.

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