12p Posted July 18, 2010 Share Posted July 18, 2010 Hi guys, I'm here again . Now I'm trying to make a Rank System so users have a motivation to continue playing. Well, this is my code. addEventHandler( "onZombieWasted", getRootElement(), function (killer) zombieKills = 0 givePlayerMoney( killer, 25 ); setElementData (killer,"zombieKills",true,zombieKills+1) if (getElementData (killer,zombieKills) == 1) then outputChatBox ("New rank! "..getPlayerName(killer).." is a Noob Killer. He killed 1 zombie.") setElementData (killer,"rank",noobKiller) end end) Console gives me ERROR at "getElementData": Bad argument. Can you tell me what's going bad here? Thanks Link to comment
Jockie Posted July 18, 2010 Share Posted July 18, 2010 (edited) You've forgot the " " @ line 6. if (getElementData (killer,zombieKills) == 1) then Turn into: if (getElementData (killer,"zombieKills") == 1) then EDIT: Also mentioned something else, you haven't set something on noobKiller @ line 8. Maybe you need to change it to: setElementData (killer,"rank","Noob killer") TIP: Use at the front of the script instead of [code]. Edited July 18, 2010 by Guest Link to comment
12p Posted July 18, 2010 Author Share Posted July 18, 2010 LOL! You answered me when I discovered it for myself . Thanks mate. But maybe I will ask for help later, so don't close this thread. EDIT: NO! the problem stills... addEvent( "onZombieWasted" ); addEventHandler( "onZombieWasted", getRootElement(), function (killer) zombieKills = 0 givePlayerMoney( killer, 25 ); setElementData (killer,"zombieKills",true,zombieKills+1) if (getElementData (killer,"zombieKills") == 1) then outputChatBox ("New rank! "..getPlayerName(killer).." is a Noob Killer. He killed 1 zombie.") setElementData (killer,"rank",noobKiller) end end) FULL CODE. Link to comment
Jockie Posted July 18, 2010 Share Posted July 18, 2010 addEvent( "onZombieWasted" ); addEventHandler( "onZombieWasted", getRootElement(), function (killer) zombieKills = 0 givePlayerMoney( killer, 25 ); setElementData (killer,"zombieKills",zombieKills+1) if (getElementData (killer,"zombieKills") == 1) then outputChatBox ("New rank! "..getPlayerName(killer).." is a Noob Killer. He killed 1 zombie.") setElementData (killer,"rank","Noob killer") end end ) ? EDIT: It sets the element data of zombieKills everytime to 1 when you kill a zombie. EDIT2:This will work. addEvent( "onZombieWasted" ); addEventHandler( "onZombieWasted", getRootElement(), function (killer) zombieKills = getElementData(killer, "zombieKills") if (zombieKills == "" or zombieKills == nil or zombieKills == false) then zombieKills = 0 end givePlayerMoney( killer, 25 ); setElementData (killer,"zombieKills",zombieKills+1) if (getElementData (killer,"zombieKills") == 1) then outputChatBox ("New rank! "..getPlayerName(killer).." is a Noob Killer. He killed 1 zombie.") setElementData (killer,"rank","Noob Killer") end end ) Link to comment
12p Posted July 18, 2010 Author Share Posted July 18, 2010 It works fine, but when I try this... addEvent( "onZombieWasted" ); addEventHandler( "onZombieWasted", getRootElement(), function (killer) if (zombieKills == "" or zombieKills == nil or zombieKills == false) then zombieKills = 0 end givePlayerMoney(killer, 25); setElementData (killer,"zombieKills",zombieKills+1) if (getElementData (killer,"zombieKills") == 10) then setElementData (killer,"rank","Noob") outputChatBox ("New rank! "..getPlayerName(killer).." is a Noob. He killed 10 zombies.") elseif (getElementData (killer,"zombieKills") == 100) then setElementData (killer,"rank","Beginner") outputChatBox ("New rank! "..getPlayerName(killer).." is a Beginner. He killed 100 zombies.") elseif (getElementData (killer,"zombieKills") == 1000) then setElementData (killer,"rank","Medium") outputChatBox ("New rank! "..getPlayerName(killer).." is a Medium. He killed 1000 zombies.") elseif (getElementData (killer,"zombieKills") == 10000) then setElementData (killer,"rank","Experiencied") outputChatBox ("New rank! "..getPlayerName(killer).." is an Experienced. He killed 10000 zombies.") elseif (getElementData (killer,"zombieKills") == 100000) then setElementData (killer,"rank","Assassin") outputChatBox ("New rank! "..getPlayerName(killer).." is an Assassin. He killed 1000000 zombies.") elseif (getElementData (killer,"zombieKills") == 1000000) then setElementData (killer,"rank","God") outputChatBox ("New rank! "..getPlayerName(killer).." is a God. He killed one million zombies!!!") end end ) It stops working fine D:. There is no Warnings or Errors shown in "debugscript 3" mode. But it doesn't show me when I got a new rank... What's going on now? Thanks to you for trying do the best. Link to comment
Jockie Posted July 18, 2010 Share Posted July 18, 2010 You've forgot a line, how to know the old data of kills. Add between line 3 and 4. zombieKills = getElementData(killer, "zombieKills") Link to comment
12p Posted July 18, 2010 Author Share Posted July 18, 2010 OK, now it works fine. EDIT: LAST THING... I'm making that the SQL saves your actual state on each killing, but... Error at line 21 (executeSQLUpdate): Bad argument. addEventHandler ("onResourceStart",getRootElement(), function () executeSQLCreateTable ("zKills","player BLOB,rank TEXT,kills INTEGER") end) addEvent("onZombieWasted") addEventHandler( "onZombieWasted", getRootElement(), function (killer) name = getPlayerName(killer) rank = getElementData(killer,"rank") zombieKills = getElementData(killer, "zombieKills") if (zombieKills == "" or zombieKills == nil or zombieKills == false) then zombieKills = 0 end givePlayerMoney (killer, 25); setElementData (killer,"zombieKills",zombieKills+1) result = executeSQLSelect ( "zKills", "player", "player = 'name'" ) if ( result == false ) then executeSQLInsert ( "zKills", "'name', 'rank', 'zombieKills'" ) else executeSQLUpdate ( "zKills", "player = 'name', rank = 'rank', kills = 'zombieKills'" ) end if (getElementData (killer,"zombieKills") == 10) then setElementData (killer,"rank","Noob") outputChatBox ("New rank! "..getPlayerName(killer).." is now a Noob. He has killed 10 zombies.") outputChatBox ("Congratulations for your new rank! You get $500 as reward.",killer,0,255,0) givePlayerMoney (killer,500) elseif (getElementData (killer,"zombieKills") == 100) then setElementData (killer,"rank","Beginner") outputChatBox ("New rank! "..getPlayerName(killer).." is now a Beginner. He has killed 100 zombies.") outputChatBox ("Congratulations for your new rank! You get $1000 as reward.",killer,0,255,0) givePlayerMoney (killer,1000) elseif (getElementData (killer,"zombieKills") == 1000) then setElementData (killer,"rank","Medium") outputChatBox ("New rank! "..getPlayerName(killer).." is now a Medium. He has killed 1000 zombies.") outputChatBox ("Congratulations for your new rank! You get $5000 as reward.",killer,0,255,0) givePlayerMoney (killer,5000) elseif (getElementData (killer,"zombieKills") == 10000) then setElementData (killer,"rank","Experiencied") outputChatBox ("New rank! "..getPlayerName(killer).." is now an Expert. He has killed 10000 zombies.") outputChatBox ("Congratulations for your new rank! You get $50000 as reward.",killer,0,255,0) givePlayerMoney (killer,50000) elseif (getElementData (killer,"zombieKills") == 100000) then setElementData (killer,"rank","Assassin") outputChatBox ("New rank! "..getPlayerName(killer).." is now an Assassin. He has killed 1000000 zombies.") outputChatBox ("Congratulations for your new rank! You get $500000 as reward.",killer,0,255,0) givePlayerMoney (killer,500000) elseif (getElementData (killer,"zombieKills") == 1000000) then setElementData (killer,"rank","God") outputChatBox ("New rank! "..getPlayerName(killer).." is now a God. He has killed one million zombies!!!") outputChatBox ("Congratulations for your new rank! You get $1000000 as reward.",killer,0,255,0) givePlayerMoney (killer,1000000) end end ) Thanks for helping me. And sorry for asking too much for help, but I'm just learning how LUA works, and I'm learning fast, too. Link to comment
50p Posted July 18, 2010 Share Posted July 18, 2010 I can't give you straight answer and correct the code for you because you wouldn't learn at all but you need to learn SQL queries if you don't know how it works and what string is in programming/scripting languages. You also need to know what variables are and how to concatenate strings in Lua. I know there will be someone who will correct the code for you but I'm trying to teach you something. Link to comment
12p Posted July 18, 2010 Author Share Posted July 18, 2010 OK, I understand that. And I know that is a bit hard to teach that theme. PS: Anyway, I'm understanding how SQL works. Maybe is not too hard teach TO ME that. PS2: Does LUA is based in C? Link to comment
50p Posted July 18, 2010 Share Posted July 18, 2010 If you know how SQL works, then what are you trying to do here: executeSQLUpdate ( "zKills", "player = 'name', rank = 'rank', kills = 'zombieKills'" ) Link to comment
12p Posted July 18, 2010 Author Share Posted July 18, 2010 executeSQLUpdate ( "zKills", "player = 'name', rank = 'rank', kills = 'zombieKills'" ) executeSQLUpdate: is to update the actual stats of the player (the kills, the rank and the name) "zkills" is the table that I made in the SQL, that contains the columns "player", "rank", and "kills". 'name', 'rank', and 'zombieKills' are predefined variables/columns: name = getPlayerName(killer) rank = getElementData(killer,"rank") zombieKills = getElementData(killer, "zombieKills") Well, what I'm doing there? I'm trying to update SQL data from the actual data of the player (defined by variables, because there are some troubles using complete sintax of functions), that is saved in the server as temporal data (I guess). But I don't know why it doesn't work. Link to comment
50p Posted July 18, 2010 Share Posted July 18, 2010 But you're not doing what you think you are... 'name' is string. name is a variable. See the difference. Have you even clicked at the links I gave you in previous post? Link to comment
12p Posted July 18, 2010 Author Share Posted July 18, 2010 LOL! I did not... But is a bit hard to me learning via reading, I learn well when I fail, because... English is not my native language, so is a bit hard to read english books, more programming books or texts. But I can understand everything that another person says, even if he's talking about programming (because they tell me it with easy words ). Okay, I'll try to understand those links (sorry for not reading it ). Thank you for your helping. 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