TheGhost Posted November 10, 2010 Share Posted November 10, 2010 Hello, My current script is in need for some attention. Here is the concept. This script assesses a player's kills and then converts that to setElementData "class" (I can't use rank as I use the tdm gamemode). When a player reachers, say, 5 kills he is promoted to Sergeant by way of integer. The command /rank is suppose to tell the player what rank/"class" the player is. Unfortunately it does not do that. I believe it has to do with the playerSource, attacker mismatch. But i am not sure. Also, my setElementHealth does not maximize the health bar, what is the proper function? local g_Root = getRootElement function welcome () local joinedPlayerName = getPlayerName ( source ) outputChatBox ( "Welcome " .. joinedPlayerName .. " to World at War!" , source, 255, 255, 255 ) end addEventHandler ( "onPlayerJoin", getRootElement(), welcome ) function setup () setElementData (source, "class", 1) setPlayerMoney (source, 25000) setElementHealth (source, 200) setPlayerArmor (source, 100) end addEventHandler ( "onPlayerSpawn", getRootElement(), setup ) function player_Wasted ( ammo, attacker, weapon, bodypart ) local killerscore = getElementData (attacker, "kills" ) if ( attacker ) then if ( getElementType ( attacker ) == "player" ) then local name = getPlayerName ( attacker ) if killerscore == 2 then outputChatBox (name.." has been promoted to Sergeant" ) setElementData (name, "class", 2) end if killerscore == 5 then outputChatBox (name.." has been promoted to Lieutenant" ) setElementData (name, "class", 3) end if killerscore == 8 then outputChatBox (name.." has been promoted to Major" ) setElementData (name, "class", 4) end if killerscore == 12 then outputChatBox (name.." has been promoted to Colonel" ) setElementData (name, "class", 5) end if killerscore == 16 then outputChatBox (name.." has been promoted to General" ) setElementData (name, "class", 6) end elseif ( getElementType ( attacker ) == "vehicle" ) then local driver = getPlayerName ( getVehicleController ( attacker ) ) if killerscore == 2 then outputChatBox (driver.." has been promoted to Sergeant" ) setElementData (driver, "class", 2) end if killerscore == 5 then outputChatBox (driver.." has been promoted to Lieutenant" ) setElementData (driver, "class", 3) end if killerscore == 8 then outputChatBox (driver.." has been promoted to Major" ) setElementData (driver, "class", 4) end if killerscore == 12 then outputChatBox (driver.." has been promoted to Colonel" ) setElementData (driver, "class", 5) end if killerscore == 16 then outputChatBox (driver.." has been promoted to General" ) setElementData (driver, "class", 6) end end end end addEventHandler ( "onPlayerWasted", g_Root (), player_Wasted ) function processClass (playerSource, commandName) local levelr = getElementData (playerSource, "class") if levelr == 1 then outputChatBox ( "You are a Private" , playerSource ) end if levelr == 2 then outputChatBox ( "You are a Sergeant", playerSource ) end if levelr == 3 then outputChatBox ( "You are a Lieutenant", playerSource ) end if levelr == 4 then outputChatBox ( "You are a Major", playerSource ) end if levelr == 5 then outputChatBox ( "You are a Colonel", playerSource ) end if levelr == 6 then outputChatBox ( "You are a General", playerSource ) end end addCommandHandler ("rank", processClass) function consoleSetKills(playerSource, commandName, kills) setElementData (playerSource, "kills", tonumber(kills)) end addCommandHandler("sk", consoleSetKills) function consoleSetDeaths(playerSource, commandName, deaths) setElementData (playerSource, "deaths", tonumber(deaths)) end addCommandHandler("sd", consoleSetDeaths) Link to comment
dzek (varez) Posted November 10, 2010 Share Posted November 10, 2010 max health is 1000 afair (or 200? not sure, one was for vehicles, other - for peds). Link to comment
Discord Moderators Zango Posted November 10, 2010 Discord Moderators Share Posted November 10, 2010 vehicles is 1000, peds are 100 Link to comment
dzek (varez) Posted November 10, 2010 Share Posted November 10, 2010 peds with health stats to max = 200 Link to comment
Discord Moderators Zango Posted November 10, 2010 Discord Moderators Share Posted November 10, 2010 Oh damn, my bad misread it Link to comment
TheGhost Posted November 10, 2010 Author Share Posted November 10, 2010 Unfortunately the script debugs fine. But I can't getElementData "class" to function. Link to comment
Castillo Posted November 11, 2010 Share Posted November 11, 2010 hmm, i didn't understand what is wrong at your script, can you explain me so i can try to help you? Link to comment
TheGhost Posted November 11, 2010 Author Share Posted November 11, 2010 There is no 'problem' per se (the /debugscript 3 does not output anything), but when one uses the command /rank, nothing appears in the chatbox, which makes me wonder if the data "class" is not truely set. You see, I am maybe 2 or 3 weeks old in scripting Lua (with only a high school semester of experience of Visual Basic 2005 under my belt previously and the holy wiki bible) and I am not aware how I can know for SURE a player's "class" other than "(driver.." has been promoted to General" )" and "setElementData (name, "class", 6)" is enough. " I need to make sure that it is set because I plan for players to attain rights based on this. For example, I hope to edit the superweapons resource to only nuke script and make it so that a player can use a nuclear bomb when he reaches colonel. Also, i want to integrate mines resource into this "class" system. My server will/does function similarily to Call of Duty, Medal of Honor, Battlefield multiplayer and the use of ranks will be epic. One of my plans is to place an insignia somewhere either on screen or above the player's head. This insignia is rooted in the "class" integer. Ideally the command will only be used for testing purposes and removed in the end. But because the command /rank doesn't output to chatbox, I questioned if "class" was really set (it took me maybe five mins to make this script so maybe I overlooked something). Link to comment
Castillo Posted November 11, 2010 Share Posted November 11, 2010 you're doing something wrong here, why need to add this line?: setElementData (name, "class", 2) when you got the player element already which is "attacker" (p.s: i think should be "killer" not attacker). Edit: the /rank cmd works fine i used runcode to setElementData on me like this: castillo = getPlayerFromName("[mm]castillo") setElementData(castillo,"class",6) then returns You are a General. Link to comment
TheGhost Posted November 11, 2010 Author Share Posted November 11, 2010 "you're doing something wrong here, why need to add this line?: setElementData (name, "class", 2) when you got the player element already which is "attacker" (p.s: i think should be "killer" not attacker)." I literally took wiki's application of a command and edited to fit mine. If you were to look at my scripts, you would see I love (local x = y) and overusing that. Anyway I am confused what you are questioning. Are you questioning my use of name when i already have attacker (which will be changed to killer)? Are you questioning why I am setting data = "class" when I could just place an if-then statement in other resources that reflects players kills. I should have mentioned before, this script was originally developing within the tdm resource. But I could not get scoreboard to react to my "Class" call, so I made it this way. Link to comment
Castillo Posted November 11, 2010 Share Posted November 11, 2010 i mean when you do setElementData(name,"class",whatever) do setElementData(attacker,"class",whatever) Link to comment
TheGhost Posted November 11, 2010 Author Share Posted November 11, 2010 did that before, get no results. no matter what i put for the element ( attacker, killer, player source, player, name, driver, Ghostmaster5000... hahha i cant get it to follow cmd. Link to comment
Castillo Posted November 11, 2010 Share Posted November 11, 2010 well i havent anyone to test it so i can't find the error. Edit: you're killing a player to test this, right? Link to comment
TheGhost Posted November 11, 2010 Author Share Posted November 11, 2010 It's fine. Im hoping that by setElementData (attacker, "class", x), I can have this insignia, nuclear weapons, and mines somehow. Link to comment
Castillo Posted November 11, 2010 Share Posted November 11, 2010 so.. its working now? Link to comment
TheGhost Posted November 11, 2010 Author Share Posted November 11, 2010 yes i was killing a player. Actually i was being killed. Im that generous. no its not working as far as i know;I am currently at the Penn State library doing Public Policy hax. I didnt change anything. But how did you get.... "Edit: the /rank cmd works fine i used runcode to setElementData on me like this: castillo = getPlayerFromName("[mm]castillo") setElementData(castillo,"class",6) then returns You are a General" EDIT: okay so i get what you did here ^^^^^ . But I can't have "castillo = getPlayerFromName("[mm]castillo")", ghost = getPlayerFromName("TheGhost")" for every player. Im going home to work on this. Thank you for your help thus far and if we I make any changes Ill be sure to post. Link to comment
TheGhost Posted November 12, 2010 Author Share Posted November 12, 2010 ok. so here my lastest version. It still doesnt work. The debugger says that some how I am using arithmatic on a boolean value. I seriously cannot figure this out. local g_Root = getRootElement function welcome () local joinedPlayerName = getPlayerName ( source ) outputChatBox ( "Welcome " .. joinedPlayerName .. " to World at War!" , source, 255, 255, 255 ) end addEventHandler ( "onPlayerJoin", getRootElement(), welcome ) function processKills () if not getElementData ( source, "points") then setElementData ( source, "points", 0) end if not getAccountData ( source, "points") then setAccountData ( source, "points", 0) end if not getAccountData ( source, "class") then setAccountData ( source, "class", 0) end if not getAccountData ( source, "amount") then setAccountData ( source, "amount", 0) end local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local playermoney = getAccountData ( source, "points" ) setElementData ( source, "points", playermoney ) end end addEventHandler("onPlayerLogin", getRootElement(), processKills ) function setup () setPlayerMoney (source, 25000) setElementHealth (source, 1000) setPlayerArmor (source, 100) end addEventHandler ( "onPlayerSpawn", getRootElement(), setup ) function player_Wasted ( ammo, attacker, weapon, bodypart ) local k = getElementData (source, "kills") --40 local p = getElementData (source, "points") local yes = k + p local r = getAccountData ( source, "points" ) local xK = getAccountData ( source, "points") local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then setAccountData( source, "points", yes ) end if ( attacker ) then if ( getElementType ( attacker ) == "player" ) then local name = getPlayerName ( attacker ) if r == 1 then outputChatBox (name.." has gotten his or her first kill and has been promoted to Private" ) --setAccountData (attacker, "class", 1) end if r == 5 then outputChatBox (name.." has been promoted to Lance Corporal" ) --setAccountData (attacker, "class", 2) end if r == 10 then outputChatBox (name.." has been promoted to Corporal" ) --setAccountData (attacker, "class", 3) end if r == 15 then outputChatBox (name.." has been promoted to Sergeant" ) --setAccountData (attacker, "class", 4) end if r == 20 then outputChatBox (name.." has been promoted to Sergeant Major" ) --setAccountData (attacker, "class", 5) end if r == 25 then outputChatBox (name.." has been promoted to Lieutenant" ) --setAccountData (attacker, "class", 6) end if r == 30 then outputChatBox (name.." has been promoted to Second Lieutenant" ) --setAccountData (attacker, "class", 7) end if r == 40 then outputChatBox (name.." has been promoted to First Lieutenant" ) --setAccountData (attacker, "class", end if r == 50 then outputChatBox (name.." has been promoted to Captain" ) --setAccountData (attacker, "class", 9) end if r == 60 then outputChatBox (name.." has been promoted to Lieutenant Major" ) --setAccountData (attacker, "class", 10) end if r == 75 then outputChatBox (name.." has been promoted to Major" ) --setAccountData (attacker, "class", 11) end if r == 100 then outputChatBox (name.." has been promoted to Lieutenant Commander" ) --setAccountData (attacker, "class", 12) end if r == 125 then outputChatBox (name.." has been promoted to Commander" ) --setAccountData (attacker, "class", 13) end if r == 150 then outputChatBox (name.." has been promoted to Lieutenant Colonel" ) --setAccountData (attacker, "class", 14) end if r == 200 then outputChatBox (name.." has been promoted to Colonel" ) setAccountData (attacker, "class", 15) end if r == 250 then outputChatBox (name.." has been promoted to Brigadier" ) setAccountData (attacker, "class", 16) end if r == 300 then outputChatBox (name.." has been promoted to Brigadier General" ) setAccountData (attacker, "class", 17) end if r == 400 then outputChatBox (name.." has been promoted to Major General" ) setAccountData (attacker, "class", 18) end if r == 500 then outputChatBox (name.." has been promoted to Lieutenant General" ) setAccountData (attacker, "class", 19) end if r == 750 then outputChatBox (name.." has been promoted to General" ) setAccountData (attacker, "class", 20) end if r == 1000 then outputChatBox (name.." has been promoted to Commander General" ) setAccountData (attacker, "class", 21) end elseif ( getElementType ( attacker ) == "vehicle" ) then local name = getPlayerName ( getVehicleController ( attacker ) ) if xK == 5 then outputChatBox (name.." has been promoted to Lance Corporal" ) --setAccounttData (attacker, "class", 2) end if xK == 10 then outputChatBox (name.." has been promoted to Corporal" ) --setAccountData (attacker, "class", 3) end if xK == 15 then outputChatBox (name.." has been promoted to Sergeant" ) --setAccountData (attacker, "class", 4) end if xK == 20 then outputChatBox (name.." has been promoted to Sergeant Major" ) setAccountData (attacker, "class", 5) end if xK == 25 then outputChatBox (name.." has been promoted to Lieutenant" ) setAccountData (attacker, "class", 6) end if xK == 30 then outputChatBox (name.." has been promoted to Second Lieutenant" ) setAccountData (attacker, "class", 7) end if xK == 40 then outputChatBox (name.." has been promoted to First Lieutenant" ) setAccountData (attacker, "class", end if xK == 50 then outputChatBox (name.." has been promoted to Captain" ) setAccountData (attacker, "class", 9) end if xK == 60 then outputChatBox (name.." has been promoted to Lieutenant Major" ) setAccountData (attacker, "class", 10) end if xK == 75 then outputChatBox (name.." has been promoted to Major" ) setAccountData (attacker, "class", 11) end if xK == 100 then outputChatBox (name.." has been promoted to Lieutenant Commander" ) setAccountData (attacker, "class", 12) end if xK == 125 then outputChatBox (name.." has been promoted to Commander" ) setAccountData (attacker, "class", 13) end if xK == 150 then outputChatBox (name.." has been promoted to Lieutenant Colonel" ) setAccountData (attacker, "class", 14) end if xK == 200 then outputChatBox (name.." has been promoted to Colonel" ) setAccountData (attacker, "class", 15) end if xK == 250 then outputChatBox (name.." has been promoted to Brigadier" ) setAccountData (attacker, "class", 16) end if xK == 300 then outputChatBox (name.." has been promoted to Brigadier General" ) setAccountData (attacker, "class", 17) end if xK == 400 then outputChatBox (name.." has been promoted to Major General" ) setAccountData (attacker, "class", 18) end if xK == 500 then outputChatBox (name.." has been promoted to Lieutenant General" ) setAccountData (attacker, "class", 19) end if xK == 750 then outputChatBox (name.." has been promoted to General" ) setAccountData (attacker, "class", 20) end if xK == 1000 then outputChatBox (name.." has been promoted to Commander General" ) setAccountData (attacker, "class", 21) end end end end addEventHandler ( "onPlayerWasted", g_Root (), player_Wasted ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local k = getElementData (source, "kills") local p = getElementData (source, "points") local playerstats = k + p setAccountData ( playeraccount, "points", playerstats ) end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) function consoleSetKills(playerSource, commandName, kills) setElementData (playerSource, "kills", tonumber(kills)) end addCommandHandler("sk", consoleSetKills)] Link to comment
Aibo Posted November 12, 2010 Share Posted November 12, 2010 function player_Wasted ( ammo, attacker, weapon, bodypart ) local k = getElementData (source, "kills") --40 local p = getElementData (source, "points") local yes = k + p and local k = getElementData (source, "kills") local p = getElementData (source, "points") local playerstats = k + p i can't see where are you setting element data for "kills", except the manual command in the end. so, probably, getElementData (source, "kills") returns false. Link to comment
TheGhost Posted November 12, 2010 Author Share Posted November 12, 2010 here is the most updated version. I cleared it up. The kills are not the problem because the kills are gathered from the default kills. But idk how to set Points. I don't understand why it thinks points boolean value yet is ok with kills. local g_Root = getRootElement function welcome () local joinedPlayerName = getPlayerName ( source ) outputChatBox ( "Welcome " .. joinedPlayerName .. " to World at War!" , source, 255, 255, 255 ) end addEventHandler ( "onPlayerJoin", getRootElement(), welcome ) function processKills () local eP = getElementData ( source, "points") if not getElementData ( source, "points") then setElementData ( source, "points", 0) end if not getAccountData ( source, "points") then setAccountData ( source, "points", 0) end local pA = getPlayerAccount ( source ) if ( pA ) then local aP = getAccountData ( source, "points" ) setElementData ( source, "points", aP ) if eP == 0 then outputChatBox ("eP == 0", source) end else outputChatBox ("eP ~= 1", source) end end addEventHandler("onPlayerLogin", getRootElement(), processKills ) function setup () setPlayerMoney (source, 25000) setElementHealth (source, 1000) setPlayerArmor (source, 100) end addEventHandler ( "onPlayerSpawn", getRootElement(), setup ) function player_Wasted ( ammo, attacker, weapon, bodypart ) local killer = getPlayerAccount ( attacker ) local eK = getElementData (attacker, "kills") local eP = getElementData (attacker, "points") local aPf = eK + eP local aP = getAccountData ( killer, "points" ) if ( killer ) then setAccountData( killer, "points", aPf ) end if ( attacker ) then if ( getElementType ( attacker ) == "player" ) then local name = getPlayerName ( attacker ) if aP == 2 then outputChatBox (name.." has gotten his or her first kill and has been promoted to Private" ) end if aP == 5 then outputChatBox (name.." has been promoted to Lance Corporal" ) end if aP == 10 then outputChatBox (name.." has been promoted to Corporal" ) end if aP == 15 then outputChatBox (name.." has been promoted to Sergeant" ) end if aP == 20 then outputChatBox (name.." has been promoted to Sergeant Major" ) end if aP == 25 then outputChatBox (name.." has been promoted to Lieutenant" ) setAccountData (attacker, "platoon", true) end if aP == 30 then outputChatBox (name.." has been promoted to Second Lieutenant" ) end if aP == 40 then outputChatBox (name.." has been promoted to First Lieutenant" ) end if aP == 50 then outputChatBox (name.." has been promoted to Captain" ) setAccountData (attacker, "company", true) end if aP == 60 then outputChatBox (name.." has been promoted to Lieutenant Major" ) end if aP == 75 then outputChatBox (name.." has been promoted to Major" ) end if aP == 100 then outputChatBox (name.." has been promoted to Lieutenant Commander" ) setAccountData (attacker, "regiment", true) end if aP == 125 then outputChatBox (name.." has been promoted to Commander" ) end if aP == 150 then outputChatBox (name.." has been promoted to Lieutenant Colonel" ) end if aP == 200 then outputChatBox (name.." has been promoted to Colonel" ) setAccountData (attacker, "brigade", true) end if aP == 250 then outputChatBox (name.." has been promoted to Brigadier" ) end if aP == 300 then outputChatBox (name.." has been promoted to Brigadier General" ) setAccountData (attacker, "nukes", true) end if aP == 400 then outputChatBox (name.." has been promoted to Major General" ) end if aP == 500 then outputChatBox (name.." has been promoted to Lieutenant General" ) end if aP == 750 then outputChatBox (name.." has been promoted to General" ) end if aP == 1000 then outputChatBox (name.." has been promoted to Commander General" ) end elseif ( getElementType ( attacker ) == "vehicle" ) then local name = getPlayerName ( getVehicleController ( attacker ) ) if aP == 5 then outputChatBox (name.." has been promoted to Lance Corporal" ) end if aP == 10 then outputChatBox (name.." has been promoted to Corporal" ) end if aP == 15 then outputChatBox (name.." has been promoted to Sergeant" ) end if aP == 20 then outputChatBox (name.." has been promoted to Sergeant Major" ) end if aP == 25 then outputChatBox (name.." has been promoted to Lieutenant" ) setAccountData (attacker, "platoon", true) end if aP == 30 then outputChatBox (name.." has been promoted to Second Lieutenant" ) end if aP == 40 then outputChatBox (name.." has been promoted to First Lieutenant" ) end if aP == 50 then outputChatBox (name.." has been promoted to Captain" ) setAccountData (attacker, "company", true) end if aP == 60 then outputChatBox (name.." has been promoted to Lieutenant Major" ) end if aP == 75 then outputChatBox (name.." has been promoted to Major" ) end if aP == 100 then outputChatBox (name.." has been promoted to Lieutenant Commander" ) setAccountData (attacker, "regiment", true) end if aP == 125 then outputChatBox (name.." has been promoted to Commander" ) end if aP == 150 then outputChatBox (name.." has been promoted to Lieutenant Colonel" ) end if aP == 200 then outputChatBox (name.." has been promoted to Colonel" ) setAccountData (attacker, "brigade", true) end if aP == 250 then outputChatBox (name.." has been promoted to Brigadier" ) end if aP == 300 then outputChatBox (name.." has been promoted to Brigadier General" ) setAccountData (attacker, "nukes", true) end if aP == 400 then outputChatBox (name.." has been promoted to Major General" ) end if aP == 500 then outputChatBox (name.." has been promoted to Lieutenant General" ) end if aP == 750 then outputChatBox (name.." has been promoted to General" ) end if aP == 1000 then outputChatBox (name.." has been promoted to Commander General" ) end end end end addEventHandler ( "onPlayerWasted", g_Root (), player_Wasted ) function onPlayerQuit ( ) local pA = getPlayerAccount ( source ) if ( pA ) then local eK = getElementData (source, "kills") local eP = getElementData (source, "points") local aP = eP + eP setAccountData ( pA, "points", playerstats ) end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) Link to comment
Aibo Posted November 12, 2010 Share Posted November 12, 2010 https://wiki.multitheftauto.com/wiki/GetAccountData getAccountData/setAccountData requires player account, not player element, try using getAccountData(getPlayerAccount(source), "points") P.S.: just noticed you got the account in pA variable, why not use it in getAccountData? and onPlayerLogin event also sends account to the function 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