Jump to content

slotman

Members
  • Posts

    64
  • Joined

  • Last visited

Posts posted by slotman

  1. Exp up but Level no up. Zombie sever

    Client

    function levelup () 
        local Exp = getElementData(localPlayer,"ExP") 
        local Level = getElementData(localPlayer,"Level") 
        if isElement(expLabel) then destroyElement(expLabel) end 
        expLabel = guiCreateLabel(0.777,0.22,0.1708,0.0963,"ExP gained: ??\nTotal ExP: ".. tostring(Exp) .."\nLevel: ".. tostring(Level),true) 
        guiLabelSetColor(expLabel,0,255,0) 
        guiLabelSetVerticalAlign(expLabel,"top") 
        guiLabelSetHorizontalAlign(expLabel,"left",false) 
        guiSetFont(expLabel,"clear-normal") 
        setTimer ( levelup, 2000, 1) 
    end 
    setTimer ( levelup, 2000, 1) 
    

     

    Server

    exports.scoreboard:scoreboardAddColumn("ExP") 
    exports.scoreboard:scoreboardAddColumn("Level") 
    local levels = {[30] = 1, [55] = 2, [75] = 3, [85] = 4, [95] = 5, [120] = 6, [150] = 7, [230] = 8, [350] = 9, [500] = 10} 
      
    addEvent("onZombieWasted",true) 
    addEventHandler("onZombieWasted",root, 
    function (killer) 
        addPlayerZombieKills(killer) 
    end) 
      
    function addPlayerZombieKills(killer) 
        local account = getPlayerAccount(killer) 
        if isGuestAccount(account) then return end 
            local H = getElementData(killer, "ExP") 
            local S = getElementData(killer, "Level") 
            setElementData(killer, "ExP", tonumber(H)+5) 
            if levels[tonumber(H)] then 
                setElementData(killer, "Level", "lvl ".. tostring(levels[tonumber(H)]) .." !") 
                triggerClientEvent ( killer, "playSound", killer ) 
            end 
        end 
      
    function onLogin (_,account) 
        setElementData(source, "Level", getAccountData(account, "lvl") or "Level 0 !") 
        setElementData(source, "ExP", getAccountData(account, "exp") or "0") 
    end 
    addEventHandler ("onPlayerLogin", root, onLogin) 
      
    function saveData(thePlayer, theAccount) 
        if (theAccount and not isGuestAccount(theAccount)) then 
            setAccountData (theAccount, "lvl", getElementData(thePlayer, "Level")) 
            setAccountData (theAccount, "exp", getElementData(thePlayer, "ExP")) 
        end 
    end 
      
    addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) 
    addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) 
    

  2. WARNNING:Bad 'ped' pointer @ 'getPedOccupiedVehicle'

    link 36

    Server

    local carFuel = {}; 
    local gasStations = {};
    local gasStationsBlip = {};
    local gasStationsMarkers = {};
    addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
        function()
            local xml = xmlLoadFile("carData.xml");
            local xmlNodes = xmlNodeGetChildren(xml);
            for i,node in ipairs(xmlNodes) do
               carFuel[tonumber(xmlNodeGetAttribute(node,'id'))] = tonumber(xmlNodeGetAttribute(node,'fuel'));
            end
            xmlUnloadFile(xml);
            local xml = xmlLoadFile("garageData.xml");
            local xmlNodes = xmlNodeGetChildren(xml);
            for i,node in ipairs(xmlNodes) do
                local name = xmlNodeGetAttribute(node,'name');
                local x = tonumber(xmlNodeGetAttribute(node,'x'));
                local y = tonumber(xmlNodeGetAttribute(node,'y'));
                local z = tonumber(xmlNodeGetAttribute(node,'z'));
                gasStationsBlip[name] = createBlip(x,y,z,51,0,0,0,0,0,0,450);
                local moreKids = xmlNodeGetChildren(node);
                gasStationsMarkers[name] = {};
                for i,v in ipairs(moreKids) do
                    local mx = tonumber(xmlNodeGetAttribute(v,'x'));
                    local my = tonumber(xmlNodeGetAttribute(v,'y'));
                    local mz = tonumber(xmlNodeGetAttribute(v,'z'));
                    gasStationsMarkers[name][i] = createMarker(mx,my,mz,'corona',3,128,128,0,128);
                    setElementData(gasStationsMarkers[name][i],'gasStation',true);
                end
            end
            xmlUnloadFile(xml);
        end
    )
     
    function fuelUse(p)
        local vehicle = getPedOccupiedVehicle(p);
        if vehicle then
            setTimer(fuelUse,1000,1,p);
            if getVehicleType(vehicle) ~= 'Automobile' and getVehicleType(vehicle) ~= 'Bike' and getVehicleType(vehicle) ~= 'Monster Truck' and getVehicleType(vehicle) ~= 'Quad' then return end
            if getVehicleController(vehicle) ~= p then return end --###
            if getVehicleEngineState(vehicle) == false then return end --###
           
            local fuel = getCarFuel(vehicle)
            if fuel == 0 then setVehicleEngineState(vehicle,false); return end --###
           
            --[[local speedX, speedY, speedZ = getElementVelocity(vehicle);
            vel = (speedX^2 + speedY^2 + speedZ^2)^(0.5)+(math.random(100,1000)/25000);]]
            local newX,newY,newZ = getElementPosition(vehicle);
            local oldX = getElementData(vehicle,'oldX') or newX;
            local oldY = getElementData(vehicle,'oldY') or newY;
            local oldZ = getElementData(vehicle,'oldZ') or newZ;
            local vel = (getDistanceBetweenPoints2D(oldX,oldY,newX,newY)/70)+(math.random(100,1000)/50000);
           
            local oldX = setElementData(vehicle,'oldX',newX);
            local oldY = setElementData(vehicle,'oldY',newY);
            local oldZ = setElementData(vehicle,'oldZ',newZ)
           
            --if vel < 0.01 then return end --###
           
            local remainingFuel = takeCarFuel(vehicle,vel);
            if remainingFuel < 0.001 then
                remainingFuel = 0;
                outputChatBox('Your car has ran out of fuel.',v);
                setVehicleEngineState(vehicle,false);
            end
        end
    end
     
    function startFuelUse(p,seat,jacked)
        if getVehicleType(source) ~= 'Automobile' and getVehicleType(source) ~= 'Bike' and getVehicleType(source) ~= 'Monster Truck' and getVehicleType(source) ~= 'Quad' then return end
        if seat ~= 0 then return end
        if getCarFuel(source) <= 0 then setVehicleEngineState(source,false); end
        setTimer(fuelUse,1000,1,p);
    end
    addEventHandler("onVehicleEnter",getRootElement(),startFuelUse)
     
    function switchEngine(playerSource)
        local theVehicle = getPedOccupiedVehicle(playerSource);
        if theVehicle and getVehicleController(theVehicle) == playerSource then
            local state = getVehicleEngineState(theVehicle)
            if state then
                setVehicleEngineState(theVehicle, false);
                outputChatBox('Car engine turned off.',playerSource);
            else
                if getCarFuel(theVehicle) <= 0 then return end
                setVehicleEngineState(theVehicle, true);
                outputChatBox('Car engine turned on.',playerSource);
            end
        end
    end
    addCommandHandler("engine",switchEngine);
     
    addEvent('pedSyphonVehicle',true);
    function pedSyphon(v)
        if getCarFuel(source) >= carFuel[-1] then outputChatBox("You are holding as much fuel as you can carry.",source); return end
        local n = math.random(100,200)/1000;
        local left = takeCarFuel(v,n);
        local total = addCarFuel(source,n);
        if left <= 0 then outputChatBox("That car has no more fuel left.",source); return end
        triggerClientEvent("onPedSyphonFuel",source);
    end
    addEventHandler('pedSyphonVehicle',getRootElement(),pedSyphon);
     
    addEvent('pedRefuelVehicle',true);
    function pedSyphon(v)
        if getCarFuel(source) <= 0 then outputChatBox("You have no more fuel left.",source); return end
        local maxFuel = carFuel[0];
        if carFuel[getElementModel(v)] then
            maxFuel = getFuel[getElementModel(v)];
        end
        if getCarFuel(v) >= maxFuel then
            outputChatBox("That car is fully refueled.",source); return
        end
        local n = math.random(100,200)/1000;
        local left = takeCarFuel(source,n);
        local total = addCarFuel(v,n);
        triggerClientEvent("onPedReFuel",source);
    end
    addEventHandler('pedRefuelVehicle',getRootElement(),pedSyphon);
     
    addEvent('onVehicleRefuel',true);
    function vehicleRefuel(v,m)
        if not getElementData(m,'gasStation') then return end
        if getElementType(v) ~= 'vehicle' then return end
        if getVehicleType(v) ~= 'Automobile' and getVehicleType(v) ~= 'Bike' and getVehicleType(v) ~= 'Monster Truck' and getVehicleType(v) ~= 'Quad' then return end
        local driver = getVehicleOccupants(v);
        if not driver[0] then return end
        if not isElementWithinMarker(v,m) then return end --###
        local maxFuel = carFuel[0];
        if getPlayerMoney(driver[0]) < 25 then outputChatBox("You can't afford any more fuel.",p); return end
        if carFuel[getElementModel(v)] then
            maxFuel = carFuel[getElementModel(v)];
        end
        if getCarFuel(v) >= maxFuel then return end
        addCarFuel(v,15);
        takePlayerMoney(driver[0],25);
        if getCarFuel(v) >= maxFuel then outputChatBox("Your car has been fully refueled.",p); takeCarFuel(v,getCarFuel(v)-maxFuel); return end
        setTimer(vehicleRefuel,500,1,v,m);
    end
    addEventHandler('onVehicleRefuel',getRootElement(),vehicleRefuel);
     
    function hitTheMarker(e)
        setTimer(vehicleRefuel,1500,1,e,source);
    end
    addEventHandler('onMarkerHit',getRootElement(),hitTheMarker);
     
    function getCarFuel(v)
        if getElementType(v) == 'vehicle' then
            if getVehicleType(v) == 'Automobile' or getVehicleType(v) == 'Bike' or getVehicleType(v) == 'Monster Truck' or getVehicleType(v) == 'Quad' then
                local fuel = getElementData(v,'fuel');
                local model = getElementModel(v);
                if not carFuel[model] then model = 0; end
                if not fuel then
                    if carFuel[model] then
                        fuel = carFuel[model];
                        setElementData(v,'fuel',carFuel[model]);
                    else
                        fuel = carFuel[0];
                        setElementData(v,'fuel',carFuel[0]);
                    end
                end
                return fuel;
            end
        elseif getElementType(v) == 'player' then
            local fuel = getElementData(v,'fuel');
            if not fuel then
                setElementData(v,'fuel',0);
                return 0;
            end
            return fuel;
        end
    end
     
    function addCarFuel(v,a)
        if getElementType(v) == 'vehicle' then
            if getVehicleType(v) == 'Automobile' or getVehicleType(v) == 'Bike' or getVehicleType(v) == 'Monster Truck' or getVehicleType(v) == 'Quad' then
                local fuel = getElementData(v,'fuel');
                local model = getElementModel(v);
                if not carFuel[model] then model = 0; end
                if not fuel then
                    if carFuel[model] then
                        fuel = carFuel[model];
                        setElementData(v,'fuel',carFuel[model]);
                    else
                        fuel = carFuel[0];
                        setElementData(v,'fuel',carFuel[0]);
                    end
                end
                fuel = fuel + a;
                if fuel > carFuel[model] then fuel = carFuel[model]; end
                setElementData(v,'fuel',fuel);
                return fuel;
            end
        elseif getElementType(v) == 'player' then
            local fuel = getElementData(v,'fuel');
            if not fuel then
                fuel = 0;
            end
            fuel = fuel + a;
            if fuel > carFuel[-1] then fuel = carFuel[-1]; end
            setElementData(v,'fuel',fuel);
            return fuel;
        end
    end
     
    function takeCarFuel(v,a)
        if getElementType(v) == 'vehicle' then
            if getVehicleType(v) == 'Automobile' or getVehicleType(v) == 'Bike' or getVehicleType(v) == 'Monster Truck' or getVehicleType(v) == 'Quad' then
                local fuel = getElementData(v,'fuel');
                local model = getElementModel(v);
                if not carFuel[model] then model = 0; end
                    if not fuel then
                    if carFuel[model] then
                        fuel = carFuel[model];
                        setElementData(v,'fuel',carFuel[model]);
                    else
                        fuel = carFuel[0];
                        setElementData(v,'fuel',carFuel[0]);
                    end
                end
                fuel = fuel - a;
                if fuel < 0 then fuel = 0; end
                setElementData(v,'fuel',fuel);
                return fuel;
            end
        elseif getElementType(v) == 'player' then
            local fuel = getElementData(v,'fuel');
            if not fuel then
                fuel = 0;
            end
            fuel = fuel - a;
            if fuel < 0 then fuel = 0; end
            setElementData(v,'fuel',fuel);
            return fuel;
        end
    end
     
    addEvent('giveVehicleFuelOnSpawn',true);
    addEventHandler('giveVehicleFuelOnSpawn',getRootElement(),function()
        getCarFuel(source);
    end);
     
    function onVehicleRespawn(exploded)
    if getElementType(source) ~= 'vehicle' then return end
        local model = getElementModel(source);
        if not carFuel[model] then model = 0; end
            if not fuel then
            if carFuel[model] then
                setElementData(source,'fuel',carFuel[model]);
            else
               
  3. ERROR 62: Bad argument #1 to 'ipairs'

    WARNING 177: Bad argument @ 'getAccountName' [Expected element at argument 1, got boolean]

    WARNING 177: Bad argument @ 'getPlayerAccount'[Expected account at argument 1, got boolean]

    Server

    carShopMarker = createMarker (2133.59,-1149.29, 23.3, "cylinder", 3, 255, 0, 0, 127) 
    carShopMarker2 = createMarker (562, -1270, 16, "cylinder", 2, 255, 0, 0, 127) 
    carShopMarker3 = createMarker (-1954,299,34,"cylinder",2,255,0,0,127) 
    carShopMarker4 = createMarker (-1663,1208,6,"cylinder",2,255,0,0,127) 
    carShopMarker5 = createMarker (1946,2068,10,"cylinder",2,255,0,0,127) 
    createBlipAttachedTo(carShopMarker,55,2,0,255,0,0,0,200) 
    createBlipAttachedTo(carShopMarker2,55,2,0,255,0,0,0,200) 
    createBlipAttachedTo(carShopMarker3,55,2,0,255,0,0,0,200) 
    createBlipAttachedTo(carShopMarker4,55,2,0,255,0,0,0,200) 
    createBlipAttachedTo(carShopMarker5,55,2,0,255,0,0,0,200) 
      
    addEvent ("viewGUI", true) 
    function markerHit (hitPlayer, matchingDimension) 
      if (source == carShopMarker) or (source == carShopMarker2) or (source == carShopMarker3) or (source == carShopMarker4) or (source == carShopMarker5) then 
        triggerClientEvent ("viewGUI", hitPlayer) 
      end 
    end 
    addEventHandler ("onMarkerHit", getRootElement(), markerHit) 
      
    addEvent ("carShopCarBuy", true) 
    addEventHandler ("carShopCarBuy", getRootElement(),  
    function(id, cost, name) 
      if (getPlayerMoney (source) >= tonumber(cost)) then 
        outputChatBox ("Bought a " .. name, source, 255, 0, 0, false) 
        outputChatBox ("ID: " .. id, source, 255, 0, 0, false) 
        outputChatBox ("Cost: " .. cost, source, 255, 0, 0, false) 
        takePlayerMoney (source, tonumber (cost)) 
        setAccountData (getPlayerAccount (source), "funmodev2-car", tonumber(id)) 
        setAccountData (getPlayerAccount (source), "funmodev2-paintjob", 3) 
        setAccountData (getPlayerAccount (source), "funmodev2-carupg", 0) 
      else 
        outputChatBox ("You are too poor!", source, 255, 0, 0, false) 
      end 
    end) 
      
      
    addEvent ("carSpawn", true) 
    addEvent ("carDestroy", true) 
      
      
    function carSpawn () 
      if not (isGuestAccount (getPlayerAccount (source))) and not (isPedInVehicle(source)) then 
        if (getElementData (source, "hisCar")) and (getElementData (source, "hisCar") ~= nil) and (getElementType(getElementData (source, "hisCar")) == "vehicle") then 
          setElementVelocity (getElementData (source, "hisCar"), 0,0,0) 
          local x,y,z = getElementPosition (source) 
          setVehicleRotation (getElementData (source, "hisCar"), 0, 0, 0) 
          setElementPosition (getElementData (source, "hisCar"), x+2,y,z +1) 
          outputChatBox ("Car spawned.", source, 255, 0, 0) 
        elseif not (getElementData (source, "hisCar")) then 
          local accountData = getAccountData (getPlayerAccount (source), "funmodev2-car") 
          if (accountData) then 
            carID = getAccountData (getPlayerAccount (source), "funmodev2-car") 
            x,y,z = getElementPosition (source) 
            vehicle = createVehicle (carID, x +2, y, z +1) 
            setElementID (vehicle, getAccountName (getPlayerAccount(source))) 
            setElementData (source, "hisCar", vehicle) 
            outputChatBox ("Car spawned.", source, 255, 0, 0) 
            if (getAccountData (getPlayerAccount(source), "funmodev2-carupg")) then 
              local upgrades = nil 
              local upgrades = {} 
              local upgrades = getAccountData (getPlayerAccount(source), "funmodev2-carupg") 
              for i,v in ipairs (upgrades) do 
                addVehicleUpgrade (vehicle, v) 
              end 
            end 
            if (getAccountData (getPlayerAccount(source), "funmodev2-paintjob")) then 
              local paintjob = getAccountData (getPlayerAccount(source), "funmodev2-paintjob") 
              setVehiclePaintjob (vehicle, paintjob) 
            end 
            if (getAccountData (getPlayerAccount(source), "funmodev2-carcolor1")) and (getAccountData (getPlayerAccount(source), "funmodev2-carcolor2")) then 
              local c1 = getAccountData (getPlayerAccount(source), "funmodev2-carcolor1") 
              local c2 = getAccountData (getPlayerAccount(source), "funmodev2-carcolor2") 
              setVehicleColor (vehicle, c1,c2,0,0) 
            end 
          else 
            outputChatBox ("You haven't got a car.", source, 255, 0, 0) 
          end 
        else 
          outputChatBox ("You're already in a car!", source, 255, 0, 0) 
        end 
      end 
    end 
    addEventHandler ("carSpawn", getRootElement(), carSpawn) 
      
    function carDestroy ()  
      if  not (isGuestAccount (getPlayerAccount (source))) then 
        if (isPedInVehicle (source)) then 
          if (getElementID(getPedOccupiedVehicle(source)) == getAccountName (getPlayerAccount(source))) then 
            setElementHealth (getElementData (source, "hisCar"), 0) 
            destroyElement (getPedOccupiedVehicle (source)) 
            removeElementData (source, "hisCar") 
            outputChatBox ("Car Destroyed.", source, 255, 0, 0) 
          else 
            outputChatBox ("This not your car!", source, 255, 0, 0) 
          end 
        elseif (not (isPedInVehicle (source))) and (getElementData (source, "hisCar")) and (getElementData (source, "hisCar") ~= nil) then 
          car=getElementData(source, "hisCar") 
          destroyElement(car) 
          outputChatBox ("Car Destroyed.", source, 255, 0, 0) 
          removeElementData (source, "hisCar") 
        end 
      end 
    end 
    addEventHandler ("carDestroy", getRootElement(), carDestroy) 
      
    function engineSwitch () 
      if (isPedInVehicle (source)) then 
        local veh = getPedOccupiedVehicle (source) 
        if (getVehicleEngineState (veh) == true) then 
          setVehicleEngineState (veh, false) 
          outputChatBox ("Vehicle shutted down.", source, 255, 0, 0) 
        elseif (getVehicleEngineState (veh) == false) then 
          setVehicleEngineState (veh, true) 
          outputChatBox ("Vehicle started.", source, 255, 0, 0) 
        end 
      else 
        outputChatBox ("You aren't in a vehicle!", source, 255, 0, 0) 
      end 
    end 
    addEvent("engenieSwitch",true) 
    addEventHandler("engenieSwitch",getRootElement(),engineSwitch) 
      
    function lightsSwitch () 
      if (isPedInVehicle (source)) then 
        local veh = getPedOccupiedVehicle (source) 
        if (getVehicleOverrideLights(veh) ~= 2) then 
          setVehicleOverrideLights(veh, 2) 
          outputChatBox ("Vehicle lights turned on.", source, 255, 0, 0) 
        elseif (getVehicleOverrideLights(veh) ~= 1) then 
          setVehicleOverrideLights(veh, 1) 
          outputChatBox ("Vehicle lights turned off.", source, 255, 0, 0) 
        end 
      else 
        outputChatBox ("You aren't in a vehicle!", source, 255, 0, 0) 
      end 
    end 
    addEvent("lightsSwitch",true) 
    addEventHandler("lightsSwitch",getRootElement(),lightsSwitch) 
      
    function lockSwitch () 
      if (isPedInVehicle (source)) then 
        local veh = getPedOccupiedVehicle (source) 
        if not (isVehicleLocked (veh)) then 
          setVehicleLocked (veh, true) 
          setVehicleDoorsUndamageable (veh, true) 
          setVehicleDoorState (veh, 0, 0) 
          setVehicleDoorState (veh, 1, 0) 
          setVehicleDoorState (veh, 2, 0) 
          setVehicleDoorState (veh, 3, 0)  
          outputChatBox ("Vehicle locked.", source, 255, 0, 0) 
        elseif (isVehicleLocked (veh)) then 
          setVehicleLocked (veh, false) 
          setVehicleDoorsUndamageable (veh, false) 
          outputChatBox ("Vehicle unlocked.", source, 255, 0, 0) 
        end 
      else 
        outputChatBox ("You aren't in a vehicle!", source, 255, 0, 0) 
      end 
    end 
    addEvent("lockSwitch",true) 
    addEventHandler("lockSwitch",getRootElement(),lockSwitch ) 
      
    addEventHandler ("onVehicleStartEnter", getRootElement(),  
    function(player, seat, jacked, door) 
      if (isVehicleLocked (source) == true) then 
        local mannetjeNaam = getAccountName (getPlayerAccount (player)) 
        local autoNaam = getElementID (source) 
        if (mannetjeNaam == autoNaam) then 
          setVehicleLocked (source, false) 
          outputChatBox ("Vehicle unlocked!", player, 255, 0, 0, false) 
        end 
      end 
    end) 
      
    addEventHandler ("onVehicleExplode", getRootElement(),  
    function() 
      local theOwner = getAccountName (getPlayerAccount(getPlayerFromName (getElementID (source)))) 
      if (theOwner) then 
        removeElementData (theOwner, "hisCar") 
      end 
    end) 
      
    addEventHandler ("onPlayerQuit", getRootElement(),  
    function(quitType, reason, responsibleElement) 
      if (getElementData (source, "hisCar")) then 
        blowVehicle (getElementData (source, "hisCar")) 
        removeElementData (source, "hisCar") 
      end 
    end) 
      
    addEventHandler( "onResourceStop", getResourceRootElement( getThisResource() ), 
        function () 
            for i,v in ipairs (getElementsByType ("player")) do 
                if (getElementData (v, "hisCar")) then 
                    setElementHealth (getElementData (v, "hisCar"), 0) 
                    removeElementData (v, "hisCar") 
                end 
            end 
        end 
    ) 
      
    function destroyOnExplode () 
        setTimer (destroyElement, 2500, 1, source) 
    end 
    addEventHandler ("onVehicleExplode", getRootElement(), destroyOnExplode) 
      
      
    

×
×
  • Create New...