Jump to content

ArrestSystem: Errors regarding "setElementInterior"


Bilal135

Recommended Posts

It is the first time I am trying to make any arrest system, so I am a bit confused how to do it. I tried this, but it is giving me 4 - 5 errors regarding "setElementInterior".

Error: Bad argument @ setElementInterior [Expected element at argument 1]

That error comes like 4 times, with different lua lines.

My code:

function arrest( attacker, wep ) 
        local team = getPlayerTeam(attacker) 
        local police = getTeamFromName("Police") 
        local wantedlevel = getPlayerWantedLevel(source) 
        if not attacker or attacker == source or wep ~= 3 or team ~= police or wantedlevel < 1 then return end 
        outputChatBox("You have been arrested by officer "..getPlayerName(attacker).."!", source, 255, 0, 0) 
        outputChatBox("You have arrested "..getPlayerName(source)..". You have been paid: $500!", attacker, 0, 255, 0) 
        givePlayerMoney(attacker, 500) 
        setElementInterior(source, 13, 1724.33, -1625.784, 20.211) 
        end 
        if wantedlevel > 0 then 
        outputChatBox("You have been jailed for 30 minutes.", source, 255, 0, 0) 
        setTimer(function() 
        setElementInterior(source, 0, 1513.6809082031, -1698.1207275391, 14.046875) 
        end, 1800000, 1) 
        outputChatBox("Your time has been served. Behave well next time.", source, 0, 255, 0) 
        end 
        end 
        addEventHandler ( "onPlayerDamage", root, arrest) 

Link to comment

Your timer is long. (30 minutes)

under 30 minutes player could either disconnect or reconnect causing his userdata to be different and the userdata he had before is not used

So there isn't a player onto which setElementInterior would be used and that's why you get this warning

Link to comment

Also using a timer server sided you must pass argument to timer for player element, inside a timer it will loose source element as it's out of context.

Added checks to fix if player left the server earlier.

30mins is too long, consider to make it 5mins at maximum or players will leave.

setTimer(function(player) 
    if isElement(player) then 
        setElementInterior(player, 0, 1513.6809082031, -1698.1207275391, 14.046875) 
        outputChatBox("Your time has been served. Behave well next time.", player, 0, 255, 0) 
    end 
end, 1800000, 1,source) 

Link to comment

I tried this, no errors came up. But it randomly arrested me (the message in chatbox came, but didnt teleport me to the interior).

When I hit another player, nothing happens.

function arrest( attacker, wep ) 
        local team = getPlayerTeam(attacker) 
        local police = getTeamFromName("Police") 
        wantedlevel = getPlayerWantedLevel(source) 
        if not attacker or attacker == source or wep ~= 3 or team ~= police or wantedlevel < 1 then return end 
        local account = getPlayerAccount(source) 
        setAccountData(account,"jailed",true) 
        outputChatBox("You have been arrested by officer "..getPlayerName(attacker).."!", source, 255, 0, 0) 
        outputChatBox("You have arrested "..getPlayerName(source)..". You have been paid: $500!", attacker, 0, 255, 0) 
        givePlayerMoney(attacker, 500) 
        setElementInterior(source, 13, 1724.33, -1625.784, 20.211) 
        outputChatBox("You have been jailed for 5 minutes.", source, 255, 0, 0) 
        setTimer(function(player) 
        if isElement(player) then 
        setElementInterior(player, 0, 1513.6809082031, -1698.1207275391, 14.046875) 
        end 
        end, 300000, 1) 
        outputChatBox("Your time has been served. Behave well next time.", source, 0, 255, 0) 
        setAccountData(source, "jailed", false) 
        end 
        addEventHandler ( "onPlayerDamage", root, arrest) 
  
function onLogin() 
local account = getPlayerAccount(source) 
if not getAccountData(account, "jailed", true) then return end 
setTimer(setAccountData, 300000, 1, account, "jailed", false) 
end 
addEventHandler("onPlayerLogin", root, onLogin) 

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