Sande Posted April 22, 2014 Share Posted April 22, 2014 Hello, i have been created a rank system 2-3days ago. But still cant get it working. The problem is somewhere when the script gets thePlayer or gets thePlayer elementDatas. local criminal1 = { "Criminal", "Street Rat", "0" } local criminal2 = { "Criminal", "Mugger", "100" } local criminal3 = { "Criminal", "Mobster", "200" } local criminal4 = { "Criminal", "Mercenary", "300" } local criminal5 = { "Criminal", "Kingpin", "500" } local police1 = { "Police", "Trainee", "0" } local police2 = { "Police", "Officer", "100" } local police3 = { "Police", "Head officer", "200" } local police4 = { "Police", "Marshall", "300" } local police5 = { "Police", "FBI Agent", "500" } --TEAM, OCCUPATION, RANKNAME, REQUIRED ACTIONS local civilian1 = { "Civilians", "Trucker", "Trucker Wannabe", "0" } local civilian2 = { "Civilians", "Trucker", "Rookietrucker", "50" } local civilian3 = { "Civilians", "Trucker", "Transport Tycoon", "75" } local civilian4 = { "Civilians", "Trucker", "Hauler", "100" } local civilian5 = { "Civilians", "Trucker", "King of the road", "150" } local emergency1 = { "Emergency", "Medic", "EMT", "0" } local emergency2 = { "Emergency", "Medic", "Nurse", "25" } local emergency3 = { "Emergency", "Medic", "Paramedic", "50" } local emergency4 = { "Emergency", "Medic", "Doctor", "75" } local emergency5 = { "Emergency", "Medic", "Surgeon", "100" } --outputChatBox ( criminal [ 1 ] ) -- bar --outputChatBox ( criminal [ 2 ] ) -- baz --outputChatBox ( criminal [ 3 ] ) -- anything function timer() setTimer(checkIfRankUp, 5000, 0) end function checkIfRankUp() local players = getElementsByType ( "player" ) for theKey,thePlayer in ipairs(players) do if ( thePlayer ) then if getElementData ( thePlayer, "Occupation" ) == "Criminal" then local crimActions = getElementData(thePlayer, "Criminal-actions" ) local occ = getElementData(thePlayer, "Occupation") if crimActions >= 99 and crimActions <= 199 then setElementData(thePlayer, "Rank", criminal2 [ 2 ] ) elseif crimActions >= 199 and crimActions <= 299 then setElementData(thePlayer, "Rank", criminal3 [ 2 ] ) elseif crimActions >= 299 and crimActions <= 499 then setElementData(thePlayer, "Rank", criminal4 [ 2 ] ) elseif crimActions >= 499 and crimActions <= 900 then setElementData(thePlayer, "Rank", criminal5 [ 2 ] ) elseif crimActions == 0 then setElementData(thePlayer, "Rank", criminal1 [ 2 ] ) end --outputDebugString("Crimi") elseif getElementData ( thePlayer, "Occupation" ) == "Police" then local polcActions = getElementData(thePlayer, "Police-actions" ) local occ = getElementData(thePlayer, "Occupation") if polcActions >= 99 and polcActions <= 199 then setElementData(thePlayer, "Rank", police2 [ 2 ] ) elseif polcActions >= 199 and polcActions <= 299 then setElementData(thePlayer, "Rank", police3 [ 2 ] ) elseif polcActions >= 299 and polcActions <= 499 then setElementData(thePlayer, "Rank", police4 [ 2 ] ) elseif polcActions >= 499 and polcActions <= 900 then setElementData(thePlayer, "Rank", police5 [ 2 ] ) elseif polcActions == 0 then setElementData(thePlayer, "Rank", police1 [ 2 ] ) end --outputDebugString("Poli") elseif getElementData ( thePlayer, "Occupation" ) == "Trucker" then local trucActions = getElementData(thePlayer, "Trucker-actions" ) local occ = getElementData(thePlayer, "Occupation") if trucActions >= 0 and trucActions <= 49 then setElementData(thePlayer, "Rank", civilian2 [ 3 ] ) elseif trucActions>= 49 and trucActions <= 74 then setElementData(thePlayer, "Rank", civilian3 [ 3 ] ) elseif trucActions >= 74 and trucActions <= 99 then setElementData(thePlayer, "Rank", civilian4 [ 3 ] ) elseif trucActions >= 99 and trucActions <= 149 then setElementData(thePlayer, "Rank", civilian5 [ 3 ] ) elseif trucActions == 0 then setElementData(thePlayer, "Rank", civilian1 [ 3 ] ) end elseif getElementData ( thePlayer, "Occupation" ) == "Medic" then local mediActions = getElementData(thePlayer, "Medic-actions" ) local occ = getElementData(thePlayer, "Occupation") if mediActions >= 0 and mediActions <= 24 then setElementData(thePlayer, "Rank", emergency2 [ 3 ] ) elseif mediActions>= 24 and mediActions <= 49 then setElementData(thePlayer, "Rank", emergency3 [ 3 ] ) elseif mediActions>= 49 and mediActions <= 74 then setElementData(thePlayer, "Rank", emergency4 [ 3 ] ) elseif mediActions >= 74 and mediActions <= 99 then setElementData(thePlayer, "Rank", emergency5 [ 3 ] ) elseif mediActions == 0 then setElementData(thePlayer, "Rank", emergency1 [ 3 ] ) end elseif getElementData ( thePlayer, "Occupation" ) == "Freeroam" then setElementData(thePlayer, "Occupation", "Freeroam") setElementData(thePlayer, "Rank", "Insane") elseif getElementData ( thePlayer, "Occupation" ) == "Unemployed" then setElementData(thePlayer, "Occupation", "Unemployed") setElementData(thePlayer, "Rank", "Unemployed") else return end end end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), timer ) Link to comment
Sande Posted April 22, 2014 Author Share Posted April 22, 2014 No, thats one reason why i am tired to fix it. I debugged it too like it output things when it check occupation, but anything goes to debug. Also the file is in meta.xml and no errors in debug. It just doesn´t work. that criminal-actions and other elementData is setted too to my account. So i dont really know what is the problem. Link to comment
Dealman Posted April 22, 2014 Share Posted April 22, 2014 Might I ask why you don't just make use of the event onElementDataChange. Having all of that checked every 5 seconds for every player is hardly a good way of doing it Link to comment
Sande Posted April 22, 2014 Author Share Posted April 22, 2014 Lol, i never hear about: onElementData change, but i think it doesn´t working if i re-script it Link to comment
Sande Posted April 22, 2014 Author Share Posted April 22, 2014 still this shit doesnt work, no debugs. local criminal1 = { "Criminal", "Street Rat", "0" } local criminal2 = { "Criminal", "Mugger", "100" } local criminal3 = { "Criminal", "Mobster", "200" } local criminal4 = { "Criminal", "Mercenary", "300" } local criminal5 = { "Criminal", "Kingpin", "500" } local police1 = { "Police", "Trainee", "0" } local police2 = { "Police", "Officer", "100" } local police3 = { "Police", "Head officer", "200" } local police4 = { "Police", "Marshall", "300" } local police5 = { "Police", "FBI Agent", "500" } --TEAM, OCCUPATION, RANKNAME, REQUIRED ACTIONS local civilian1 = { "Civilians", "Trucker", "Trucker Wannabe", "0" } local civilian2 = { "Civilians", "Trucker", "Rookietrucker", "50" } local civilian3 = { "Civilians", "Trucker", "Transport Tycoon", "75" } local civilian4 = { "Civilians", "Trucker", "Hauler", "100" } local civilian5 = { "Civilians", "Trucker", "King of the road", "150" } local emergency1 = { "Emergency", "Medic", "EMT", "0" } local emergency2 = { "Emergency", "Medic", "Nurse", "25" } local emergency3 = { "Emergency", "Medic", "Paramedic", "50" } local emergency4 = { "Emergency", "Medic", "Doctor", "75" } local emergency5 = { "Emergency", "Medic", "Surgeon", "100" } --outputChatBox ( criminal [ 1 ] ) -- bar --outputChatBox ( criminal [ 2 ] ) -- baz --outputChatBox ( criminal [ 3 ] ) -- anything function timer() setTimer(checkIfRankUp, 5000, 0) end function checkIfRankUp(source) if getElementData ( source, "Occupation" ) == "Criminal" then local crimActions = getElementData(source, "Criminal-actions" ) local occ = getElementData(source, "Occupation") if crimActions >= 99 and crimActions <= 199 then setElementData(source, "Rank", criminal2 [ 2 ] ) elseif crimActions >= 199 and crimActions <= 299 then setElementData(source, "Rank", criminal3 [ 2 ] ) elseif crimActions >= 299 and crimActions <= 499 then setElementData(source, "Rank", criminal4 [ 2 ] ) elseif crimActions >= 499 and crimActions <= 900 then setElementData(source, "Rank", criminal5 [ 2 ] ) elseif crimActions == 0 then setElementData(source, "Rank", criminal1 [ 2 ] ) end --outputDebugString("Crimi") elseif getElementData ( source, "Occupation" ) == "Police" then local polcActions = getElementData(source, "Police-actions" ) local occ = getElementData(source, "Occupation") if polcActions >= 99 and polcActions <= 199 then setElementData(source, "Rank", police2 [ 2 ] ) elseif polcActions >= 199 and polcActions <= 299 then setElementData(source, "Rank", police3 [ 2 ] ) elseif polcActions >= 299 and polcActions <= 499 then setElementData(source, "Rank", police4 [ 2 ] ) elseif polcActions >= 499 and polcActions <= 900 then setElementData(source, "Rank", police5 [ 2 ] ) elseif polcActions == 0 then setElementData(source, "Rank", police1 [ 2 ] ) end --outputDebugString("Poli") elseif getElementData ( source, "Occupation" ) == "Trucker" then local trucActions = getElementData(source, "Trucker-actions" ) local occ = getElementData(source, "Occupation") if trucActions >= 0 and trucActions <= 49 then setElementData(source, "Rank", civilian2 [ 3 ] ) elseif trucActions>= 49 and trucActions <= 74 then setElementData(source, "Rank", civilian3 [ 3 ] ) elseif trucActions >= 74 and trucActions <= 99 then setElementData(source, "Rank", civilian4 [ 3 ] ) elseif trucActions >= 99 and trucActions <= 149 then setElementData(source, "Rank", civilian5 [ 3 ] ) elseif trucActions == 0 then setElementData(source, "Rank", civilian1 [ 3 ] ) end elseif getElementData ( source, "Occupation" ) == "Medic" then local mediActions = getElementData(source, "Medic-actions" ) local occ = getElementData(source, "Occupation") if mediActions >= 0 and mediActions <= 24 then setElementData(source, "Rank", emergency2 [ 3 ] ) elseif mediActions>= 24 and mediActions <= 49 then setElementData(source, "Rank", emergency3 [ 3 ] ) elseif mediActions>= 49 and mediActions <= 74 then setElementData(source, "Rank", emergency4 [ 3 ] ) elseif mediActions >= 74 and mediActions <= 99 then setElementData(source, "Rank", emergency5 [ 3 ] ) elseif mediActions == 0 then setElementData(source, "Rank", emergency1 [ 3 ] ) end elseif getElementData ( source, "Occupation" ) == "Freeroam" then setElementData(source, "Occupation", "Freeroam") setElementData(source, "Rank", "Insane") elseif getElementData ( source, "Occupation" ) == "Unemployed" then setElementData(source, "Occupation", "Unemployed") setElementData(source, "Rank", "Unemployed") else return end end addEventHandler("onElementDataChange",getRootElement(),checkIfRankUp) Link to comment
tosfera Posted April 22, 2014 Share Posted April 22, 2014 Could you replace your 'return' with a debug message? Maybe you've messed up with capitals or such. Link to comment
Sande Posted April 22, 2014 Author Share Posted April 22, 2014 Putted return with debug message, its all time returning. so the message is appear all time. outputDebugString("return shit") Link to comment
tosfera Posted April 22, 2014 Share Posted April 22, 2014 Putted return with debug message, its all time returning. so the message is appear all time. outputDebugString("return :~") So, with a bit of logical thinking. You should output the actual value that has been given with the dataName of "Occupation". outputDebugString ( getElementData ( source, "Occupation" ) ); Link to comment
Sande Posted April 22, 2014 Author Share Posted April 22, 2014 it gets false. but its not false in my account. Link to comment
Sande Posted April 22, 2014 Author Share Posted April 22, 2014 Problem fixxed, added: dataName,oldValue to the function arguments. 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