Jump to content

Sv . static


CapY

Recommended Posts

Posted

Why i get error at sv\server.statc:88: Bad argument @ 'setTimer'

Server:

function isNumber(n) 
    return tonumber(n) ~= nil 
end 
  
addEvent("create", true) 
addEventHandler("create", root, 
    function(glp, px, py, pz, arg2, ...) 
        if (isPedDead(glp)) then return end 
        if (isPedInVehicle(glp)) then return exitVehicle(getPedOccupiedVehicle(glp)) end 
        local _Name = table.concat({...}, " ") 
        if (_Name == "none") then return end 
        if not isNumber(_Name) and not getVehicleModelFromName(_Name) then outputChatBox("Invalid vehicle '".. _Name .."'",glp,255,0,0) return end 
        if isNumber(_Name) and not getVehicleNameFromModel(_Name) then outputChatBox("Invalid vehicle '".. _Name .."'",glp,255,0,0) return end 
        for _,v in ipairs(getElementsByType("vehicle")) do 
            if (getElementData(v, "svowner") == getPlayerName(glp)) then 
                destroyElement(v) 
            end 
        end 
        local gID = getVehicleModelFromName(_Name) 
        local nV = createVehicle(gID or tonumber(gID) or ..., px, py, pz, 0, 0, 0) 
        local gpv = getPedOccupiedVehicle(glp) 
        local vehOcc = isPedInVehicle(glp) 
        warpPedIntoVehicle(glp, nV) 
        local gpv = getPedOccupiedVehicle(glp) 
        local rz = getPedRotation(glp) 
        setVehicleRotation(gpv, 0, 0, rz) 
        setElementData(nV, "svowner", getPlayerName(glp), false) 
    end 
) 
  
addEvent("change", true) 
addEventHandler("change", root, 
    function(glp, cmd, arg2, ...) 
        local _Name = table.concat({...}, " ") 
        local gID = getVehicleModelFromName(_Name) 
        local gpv = getPedOccupiedVehicle(glp) 
        if (getPedOccupiedVehicleSeat(glp) == 0) then 
            if (_Name == "none") then return destroyElement(gpv) end 
        if not isNumber(_Name) and not getVehicleModelFromName(_Name) then outputChatBox("Invalid vehicle '".. _Name .."'",glp,255,0,0) return end 
        if isNumber(_Name) and not getVehicleNameFromModel(_Name) then outputChatBox("Invalid vehicle '".. _Name .."'",glp,255,0,0) return end 
            setElementModel(gpv, gID or tonumber(gID) or ...) 
            setElementData(gpv, "svowner", getPlayerName(glp), false) 
            if getElementData(glp, "fighting") then return end 
            fixVehicle(gpv) 
    end 
end 
) 
  
function none(source, cmd, arg) 
    if (arg == "none" and isTimer(onStart)) then 
        if (isElement(getPedOccupiedVehicle(source))) then destroyElement(getPedOccupiedVehicle(source)) end 
        if (isTimer(onStart)) then killTimer(onStart) end 
        return  end 
end 
addCommandHandler("sv", none) 
  
function destroyVehicle(vehicle) 
     local check = false 
     for _,gPlayer in ipairs(getElementsByType("player")) do 
        if (getPedOccupiedVehicle(gPlayer) == vehicle) then 
            if (getPedOccupiedVehicleSeat(gPlayer) == 0) then 
                check = true 
            end 
        end 
    end 
    if (isElement(vehicle) and getElementType(vehicle) == "vehicle" and check == false) then 
        destroyElement(vehicle) 
    end 
end 
  
addEventHandler("onVehicleStartExit", root, function(_, seat) 
    if (seat > 0) then 
        removeEventHandler("onPlayerVehicleExit", root, exitVehicle) 
    else 
        removeEventHandler("onPlayerVehicleExit", root, exitVehicle) 
        addEventHandler("onPlayerVehicleExit", root, exitVehicle) 
    end 
end 
) 
  
  
addEventHandler("onVehicleStartEnter", root, function(glp, _, _, door) 
    setElementData(source, "svowner", getPlayerName(glp), false) 
    if (getVehicleType" class="kw2">getVehicleType" class="kw2">getVehicleType(source) == "Train") then 
        setTrainDerailable(source, false) 
    end 
    if (door == 0 and getPlayerName(getVehicleOccupant(source, 0)) == getPlayerName(glp) and not isVehicleLocked(source)) then 
        onStart = setTimer(svNone, 50, 0) 
    end 
end 
) 
  
addEventHandler("onPlayerQuit", root, function() 
    for _,v in ipairs(getElementsByType("vehicle")) do 
        if (getElementData(v, "svowner") == getPlayerName(source)) then 
            destroyElement(v) 
        end 
    end 
end 
) 
  
addEventHandler("onPlayerWasted", root, function() 
    for _,v in ipairs(getElementsByType("vehicle")) do 
    if (getElementData(v, "svowner") == getPlayerName(source)) then 
    exitVehicle(v) 
        end 
    end 
end 
) 
  
function exitVehicle(vehicle) 
    if (isElement(vehicle) and getElementType(vehicle) == "vehicle") then 
    setTimer(destroyVehicle, 90000, 1, vehicle) 
    end 
end 
addEventHandler("onPlayerVehicleStartExit", root, exitVehicle) 
 

Anybody can help me with this ?

Posted

In client ,

Here:

glp = getLocalPlayer() 
notallowed = {[432] = true, [538] = true, [569] = true, [590] = true, [537] = true, [449] = true} 
spaces = {["Police Maverick"] = true, ["Mountain Bike"] = true, ["Pizza Boy"] = true, ["Utility Van"] = true, ["Police Car (Los Santos)"] = true, ["Police Car (San Fierro)"] = true, ["Police Ranger"] = true, ["FBI Rancher"] = true, ["FBI Truck"] = true, ["Fire Truck"] = true, ["Fire Truck (Ladder)"] = true, ["Police Car (Las Venturas)"] = true, ["Black Boxville"] = true, ["Linerunner (From 'Tanker Commando')"] = true, ["Mr. Whoopee"] = true, ["Cement Truck"] = true, ["Combine Harvester"] = true, ["Berkley's RC Van"] = true, ["Damaged Sadler"] = true, ["News Van"] = true, ["RC Bandit"] = true, ["RC Baron"] = true, ["RC Goblin"] = true, ["RC Raider"] = true, ["RC Tiger"] = true, ["BF Injection"] = true, ["Bloodring Banger"] = true, ["Monster 2"] = true, ["Super GT"] = true, ["Hotring Racer"] = true, ["Hotring Racer 2"] = true, ["Hotring Racer 3"] = true, ["Rancher (From 'Lure')"] = true, ["RC Cam (flower pot)"] = true, ["News Chopper"] = true } 
  
function isNumber(n) 
    return tonumber(n) ~= nil 
end 
  
addCommandHandler("sv", 
    function(cmd, carName, ...) 
        if (glp and isElement(glp) and getElementType(glp) == "player") then 
            if (not isTimer(antiSpam)) then 
            if (isPlayerDead(glp)) then return end 
            local px, py, pz = getElementPosition(glp) 
                if (carName == nil) then 
                    msg("No vehicle specified") 
                elseif not isNumber(carName) and (notallowed[getVehicleModelFromName(tostring(carName))]) then 
                    msg("Vehicle not allowed") 
                elseif isNumber(carName) and ((notallowed[tonumber(carName)]) or (notallowed[tonumber(math.floor(carName))])) then 
                    msg("Vehicle not allowed") 
                elseif (not getVehicleModelFromName(tostring(carName and ...)) and not isNumber(carName) and spaces[tostring(carName)] == false and not tostring(carName) == "none") then 
                    msg("Invalid vehicle name '" .. carName .. "'") 
                elseif (getElementInterior(glp) > 0) then 
                elseif (not isPedInVehicle(glp)) then 
                    if (isNumber(carName) and tonumber(carName) < 400 or isNumber(carName) and tonumber(carName) > 610) then 
                        cancelEvent() 
                        msg("Invalid vehicle " .. carName .. "'") 
                    else 
                        triggerServerEvent("create", glp, glp, px, py, pz, arg2, carName, ...) 
                    end 
                elseif (isPedInVehicle(glp)) then 
                    if (isNumber(carName) and tonumber(carName) < 400 or isNumber(carName) and tonumber(carName) > 610) then 
                        cancelEvent() 
                        msg("Invalid vehicle '" .. carName .. "'") 
                    else 
                        triggerServerEvent("change", glp, glp, cmd, arg2, carName, ...) 
                    end 
                end 
            antiSpam = setTimer(function() end, 70, 1) 
        else 
        end 
    end 
end 
) 
  
function msg(err) 
    outputChatBox(err,255,0,0) 
end 

Posted

What's so hard about triggering an event.

What you are doing is triggering a function that doesn't exist.

use:

triggerServerEvent 
triggerClientEvent 

Check the examples and the Introduction To Scripting GUI in the wiki for more details about the functions.

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

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