Captain Cody Posted November 29, 2015 Share Posted November 29, 2015 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 IIYAMA Posted November 29, 2015 Moderators Share Posted November 29, 2015 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
Captain Cody Posted November 29, 2015 Author Share Posted November 29, 2015 Well what I mean by debug is errors in debug-script, but I'll add those and see if I can find the issue Link to comment
Captain Cody Posted November 29, 2015 Author Share Posted November 29, 2015 (edited) --Ah nvm found it-- Edited November 29, 2015 by Guest Link to comment
ALw7sH Posted November 29, 2015 Share Posted November 29, 2015 If you mean just the line 2 debug works then are you trying to get if the player team name is "Military" OR "Police" in line 3? if not then just make sure that your team name is exactly like the one in your script Link to comment
ALw7sH Posted November 29, 2015 Share Posted November 29, 2015 --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
Captain Cody Posted November 29, 2015 Author Share Posted November 29, 2015 Edited it after I figured out how to do it. Link to comment
Captain Cody Posted November 29, 2015 Author Share Posted November 29, 2015 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
Moderators IIYAMA Posted November 29, 2015 Moderators Share Posted November 29, 2015 Which event's is attached on both function? And remember, timers don't support a source element. Link to comment
Captain Cody Posted November 29, 2015 Author Share Posted November 29, 2015 #1 Not sure what you mean by that but What start the functions are addEventHandler ( "onPlayerDamage", getRootElement (), jailOrNotPlayer ) addCommandHandler ( "jailtime", checkHisTime ) addEventHandler ( "onPlayerJoin", getRootElement(), checkIfJailed ) #2 fixed Link to comment
Moderators IIYAMA Posted November 29, 2015 Moderators Share Posted November 29, 2015 The addCommandHandler doesn't have a source element. The first argument is the player. And if that isn't the problem, you should show more of your code because I do not have enough information to debug it. Link to comment
Captain Cody Posted November 29, 2015 Author Share Posted November 29, 2015 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 IIYAMA Posted November 29, 2015 Moderators Share Posted November 29, 2015 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
Captain Cody Posted November 29, 2015 Author Share Posted November 29, 2015 How would I do serial or account name? Link to comment
Moderators IIYAMA Posted November 30, 2015 Moderators Share Posted November 30, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now