Jump to content

Yet another issue... God, I suck at scripting.


Captain Cody

Recommended Posts

  
function jailOrNotPlayer (attacker, attackerweapon, bodypart, loss) 
local PoliceTeam = getTeamFromName("Military, Police") 
if getPlayerTeam ( attacker ) == PoliceTeam  
then 
local convict = source 
if (attackerweapon == 3) then 
local level = getPlayerWantedLevel ( convict ) 
if level > 0 then 
outputChatBox ( "You have been jailed", convict ) 
setElementInterior ( convict, 6, 264.05957, 77.829102, 1001.0391 ) 
setTimer ( function(convict) -- 
setElementInterior ( convict, 0, 1541.3105, -1675.4785, 13.552299  ) 
        outputChatBox ( "You have been released", convict ) 
        initalwantedlevel = getPlayerWantedLevel ( convict ) 
        local wantedlevelaa = (initalwantedlevel * 200) 
                setPlayerWantedLevel ( convict, 0 ) 
    end, wantedlevelaa, 1 ) 
end 
end 
end 
end 
  
addEventHandler ( "onPlayerDamage", getRootElement (), jailOrNotPlayer ) 

Should jail player, showing no signs at all of jailing the player, nothing showing in debugscript

Link to comment
  • Moderators

If nothing is showing in debug script, you have to find out till where your code works.

Add debug lines after the lines: 2, 5, 7, 9, 13

A debug line is:

outputDebugString("function jailOrNotPlayer has been executed") 

In the console you will see this line, when it gets executed.

Ones you added them all, you can see how many debug-lines are executed. After the last one that is executed, there is mostly your mistake.

So for example:

outputDebugString(1) 
if true then 
    outputDebugString(2) 
    if true then 
        outputDebugString(3) 
        if true then 
            outputDebugString(4) 
            if false then 
                outputDebugString(5) 
                if false then 
                    outputDebugString(6) 
                end 
            end 
        end 
    end 
end 

The code will show the debug-lines 1,2,3,4 but not 5 and 6.

Now you know that there is a mistake between the debug-lines 4 and 5.

Link to comment
--Nvm Fixed--

But how do I do two teams for

local PoliceTeam = getTeamFromName("Military") 

local militaryTeam = getTeamFromName("Military") 
local PoliceTeam = getTeamFromName("Police") 
if getPlayerTeam ( attacker ) == militaryTeam or getPlayerTeam ( attacker ) == PoliceTeam then 

Link to comment

I added the stuff to a table so I can figureout whos in jail or not

Here's what declares the table start

jailSystemData = {}  

Here's what assigns a table to the player

jailSystemData[source] = {} 
local playerjailSystemData = jailSystemData[source] 

playerjailSystemData["Injail"] = true 

local theTimer = setTimer(function() end, (level * 40000), 1) 
playerjailSystemData["timer"] = theTimer 

Here's what pulls the data for another function

    local playerjailSystemData = jailSystemData[source] 
    if playerjailSystemData then 

It's not finding the data for the player, returns nil

Link to comment

Here's the entire code

jailSystemData = {}  
  
---Jails player if they are wanted, and are hit by police with night stick 
  
function jailOrNotPlayer (attacker, attackerweapon, bodypart, loss) 
outputDebugString("function jailOrNotPlayer has been executed") 
local PoliceTeam = getTeamFromName("Police") 
local MilitaryTeam = getTeamFromName("Military") 
if getPlayerTeam ( attacker ) == PoliceTeam or getPlayerTeam ( attacker ) == MilitaryTeam 
then 
outputDebugString("Attacker was a cop") 
local convict = source 
if (attackerweapon == 3) then 
outputDebugString("So and so was hit with night stick") 
level = getPlayerWantedLevel ( convict ) 
if level > 0 then 
theconvictName = getPlayerName (convict) 
outputChatBox ( "You have been jailed, do /jailtime to get time remaining.", convict ) 
outputChatBox ( "You have jailed" ..theconvictName.."." , attacker ) 
setElementInterior ( convict, 6, 264.05957, 77.829102, 1001.0391 ) 
setElementDimension ( convict, 1 ) 
jailSystemData[convict] = {} 
local playerjailSystemData = jailSystemData[convict] 
playerjailSystemData["injail"] = true 
outputDebugString("Person jailed") 
jailedperson = convict 
local theTimer = setTimer(function() end, (level * 40000), 1,convict) 
playerjailSystemData["timer"] = theTimer 
setTimer ( function() -- 
setElementInterior ( jailedperson, 0, 1541.3105, -1675.4785, 13.552299  ) 
    setElementDimension ( jailedperson, 0 ) 
        outputChatBox ( "You have been released.", jailedperson ) 
         outputDebugString("Person Released from jail.") 
         setPlayerWantedLevel ( jailedperson, 0 ) 
        local playerjailSystemData = jailSystemData[jailedperson] 
        playerjailSystemData["injail"] = false 
        local convict = jailedperson 
    end, (level * 40000), 1 ) 
end 
end 
end 
end 
 --Should set timer on spawn to release player if they were in jail before they left 
function checkIfJailed () 
    local playerjailSystemData = jailSystemData[source] 
    if playerjailSystemData then 
    if playerjailSystemData["injail"] 
    then 
    thejailedperson = source 
    outputChatBox ( "You are in jail do /jailtime to get amount of time remaining.", thejailedperson ) 
    local theTimer = setTimer(function() end, (level * 40000), 1,convict) 
    setTimer ( function() -- 
    setElementInterior ( thejailedperson, 0, 1541.3105, -1675.4785, 13.552299  ) 
    setElementDimension ( thejailedperson, 0 ) 
    outputChatBox ( "You have been released", thejailedperson ) 
    outputDebugString("Person Released from jail.") 
    setPlayerWantedLevel ( thejailedperson, 0 ) 
    local playerjailSystemData = jailSystemData[thejailedperson] 
    playerjailSystemData["injail"] = false 
    playerjailSystemData["timer"] = theTimer 
    end, (level * 40000), 1 ) 
end 
end 
end 
  
  
--Function for command /jailtime, shows the player how long they have left 
  
function checkHisTime () 
local playerjailSystemData = jailSystemData[source] 
if playerjailSystemData then 
local theTimer = playerjailSystemData["timer"] 
local remaining = getTimerDetails(theTimer) 
if (remaining) then 
outputChatBox("You have: "..remaining.." millisecounds remaining.", source) 
else 
outputChatBox("You are not in jail.", source) 
end 
end 
end 
  
--Event and command handlers 
addEventHandler ( "onPlayerDamage", getRootElement (), jailOrNotPlayer ) 
addCommandHandler ( "jailtime", checkHisTime ) 
addEventHandler ( "onPlayerJoin", getRootElement(), checkIfJailed ) 

Tad bit long but there's the whole thing.

Link to comment
  • Moderators
function checkHisTime (player) -- < you use addCommandHandler and not an event. 
local playerjailSystemData = jailSystemData[player] 

And the addEventHandler ( "onPlayerJoin", getRootElement(), checkIfJailed ) event in combination with a table + userdata is a bit useless. Because when a player leaves the server, his userdata becomes invalid. And when he rejoins, his userdata is not the same. You should use serials or account names for that.

Link to comment
  • Moderators
getPlayerSerial 
getPlayerAccount --[[>>]] not isGuestAccount --[[>>]] getAccountName 
--And if you are using very long jail times: 
setAccountData 
  

Replace the table key with the results of: table[getPlayerSerial] or table[getAccountName]

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