| closedMelee Death Change |
| Started by Tank on 07-01-2008, 04:05 PM |
Threads: 59
Joined: Jan 2007
Good day,rnrnThis is the first time I even attempt something like this. I never wrote a plugin before. All I've been doing in the past is reading *.sma files and tutorials about PAWN and the general scripting tutorials.rnrnMy idea was to create a plugin when people made (set by cvar) melee kills, it would add + (set by cvar) kills and - (set by cvar) deaths. Since I wanted to start out really simple, the above stated features are not yet included.rnrnAt the moment how I see it (and I already question that :D) it should do this...rnrnWhen you make a melee kill with the garandbutt it would remove (by default) 2 kills. Nothing more at the moment because I can't even get this working. Perhaps that you could give me any pointers on how to continue fixing the problems I have right now.rnrnPlease note that English aint my native language and that words like functions, cvars and others are still roaming through my mind as rather empty thoughts.rn
//////////////////////////////////////////////////////////////////////////////////rn//rn// DoD Melee ScoreBonuesrn// - Version 0.1rn// - 01.07.2008rn//rn//////////////////////////////////////////////////////////////////////////////////rn//rn// Borrowed code from:rn// dod_meleebonus created by FireStorm, updated by Diamond-Opticrn// dod_scorereward created by FireStormrn//rn//////////////////////////////////////////////////////////////////////////////////rnrn// Modules being includedrn// <fun> needed at least for ????rn// <dodx> needed at least for client_deathrn// <dodfun> needed at least for dod_get/set_pl_deathsrn#include <amxmodx>rn#include <fun>rn#include <dodx>rn#include <dodfun>rnrn// Declare vars for the cvarsrnnew p_enabled, p_decreasedeathsrnrnpublic plugin_init() rn{rn // Registering plugin rn register_plugin("Melee Score Bonus","Version 0.1","The Tank")rn // Declaring CVARS rn p_enabled = register_cvar("scorebonus_enabled","1")rn p_decrdeaths = register_cvar("scorebonus_changedeaths","2") rn // Stats forward type rn register_statsfwd(XMF_DEATH)..rn}rn// Used to set that the client diedrnpublic client_death(killer,victim,wpnindex,hitplace,TK)rn{rn // Checks if the CVAR and with that the plugin is enabledrn // Checks if the client is indeed connected <- diamond opticrn if(get_pcvar_num(p_enabled) == 1 && is_user_connected(killer))rn {rn // Checks if TeamKill is off rn if(TK == 0)rn {rn // Declares a array called killernamern new killername[32]rn get_user_name(killer,killername,31) //gets the clients usernamern new currentdeaths = dod_get_pl_deaths(killer) //gets clients deathsrn new newdeaths = get_pcvar_num(p_decrdeaths) //makes a var and sets it as the cvarrnrn if(wpnindex == DODW_GARAND_BUTT) //The weapon being checked is garandbuttrn {rn // should set clients deaths as currentdeaths - deaths entered by cvar rn dod_set_pl_deaths(killer,(currentdeaths-newdeaths))rn }rn }rn }rn return PLUGIN_HANDLEDrn}rnrnPs: I would like to thank Diamond-Optic and FireStorm for creating something I could use to help me learning how to write plugins.rnrnPs2: I know this plugin has been written once but I could not find it. Because I really would like to learn how to write plugins, I decided to use this rather small plugin to help me started.Threads: 59
Joined: Jan 2007
Because I have no idea what the compile errors mean or how to read them. To save you any effort I posted the error lines in herernrn
/home/groups/amxmodx/tmp3/phpHKJGZy.sma(21) : warning 217: loose indentationrn/home/groups/amxmodx/tmp3/phpHKJGZy.sma(23) : warning 217: loose indentationrn/home/groups/amxmodx/tmp3/phpHKJGZy.sma(23) : error 001: expected token: ";", but found ".."rn/home/groups/amxmodx/tmp3/phpHKJGZy.sma(23) : error 029: invalid expression, assumed zerorn/home/groups/amxmodx/tmp3/phpHKJGZy.sma(34) : error 017: undefined symbol "get_user_score"rn/home/groups/amxmodx/tmp3/phpHKJGZy.sma(39) : error 017: undefined symbol "set_user_score"rn/home/groups/amxmodx/tmp3/phpHKJGZy.sma(42) : error 035: argument type mismatch (argument 2)rnrn5 Errors.rnCould not locate output file /home/groups/amxmodx/public_html/websc3/phpHKJGZy.amx (compile failed).Threads: 15
Joined: Mar 2007
Here is the fixed code XD Message me on steam if you have any questions.rnrn
//////////////////////////////////////////////////////////////////////////////////rn//rn// DoD Melee ScoreBonuesrn// - Version 0.1rn// - 01.07.2008rn//rn//////////////////////////////////////////////////////////////////////////////////rn//rn// Borrowed code from:rn// dod_meleebonus created by FireStorm, updated by Diamond-Opticrn// dod_scorereward created by FireStormrn//rn//////////////////////////////////////////////////////////////////////////////////rnrn// Modules being includedrn// <fun> needed at least for ????rn// <dodx> needed at least for client_deathrn// <dodfun> needed at least for dod_get/set_pl_deathsrn#include <amxmodx>rn#include <dodfun>rnrnrnpublic plugin_init() {rn // Registering plugin rn register_plugin("Melee Score Bonus","Version 0.1","The Tank")rn // Declaring CVARS rn register_cvar("scorebonus_enabled","1")rn register_cvar("scorebonus_changedeaths","2")rn}rnrn// Used to set that the client diedrnpublic client_death(killer,victim,wpnindex,hitplace,TA) {rn rn // Checks if the CVAR and with that the plugin is enabledrn // Checks if the client is indeed connected <- diamond opticrn if(get_cvar_num("scorebonus_enabled") == 1 && is_user_connected(killer))rn {rnrn // Checks if kill was a team killrn if(TA == 0)rn {rn // Declares a array called killernamern new killername[32]rn get_user_name(killer,killername,31) //gets the clients usernamernrn if(wpnindex == 38) //The weapon being checked is garandbuttrn // Here are some more useful melee weapon numbersrn // 1 = american knifern // 2 = german knifern // 19 = shovelrn // 34 = k98 bayorn // 37 = english knifern // 38 = garand buttrn // 39 = enfield bayorn // 41 = k43 buttrn {rn // should set clients deaths as currentdeaths - deaths entered by cvarrn dod_set_pl_deaths(killer,dod_get_pl_deaths(killer) - get_cvar_num("scorebonus_changedeaths"),1)rn rn // If players deaths are less than 0 let's fix that ^_^rn if(dod_get_pl_deaths(killer) < 0)rn {rn dod_set_pl_deaths(killer,0,1)rn }rn }rn }rn }rn return PLUGIN_HANDLEDrn}Threads: 75
Joined: Jun 2006
Proper coding procedures make reading and understanding code so much more easier...none of that shit like microslot uses nor the crap from linux. Lots of space, it aint a premium like it use to be.nnCheers!
Threads: 59
Joined: Jan 2007
I think I read this reply somewhere else. That's why when Synthetic explained over Steam Chat what the changes were and why the changes were needed, he also explained me what could be done to make the code neater.
Threads: 59
Joined: Jan 2007
With a lot of help from Synthetic (you have no idea how pleased I am with you sharing your time to help me out) I came to this. There are probably some errors in the array (as the compile error log also shows) but I thought I would not need array's just yet because generally I have no knowledge about them.rnrn
//////////////////////////////////////////////////////////////////////////////////rn//rn// DoD Melee ScoreBonuesrn// - Version 0.1rn// - 01.07.2008rn//rn//////////////////////////////////////////////////////////////////////////////////rn//rn// Borrowed code from:rn// dod_meleebonus created by FireStorm, updated by Diamond-Opticrn// dod_scorereward created by FireStormrn//rn//////////////////////////////////////////////////////////////////////////////////rnrn// Modules being includedrn// <dodfun> needed at least for dod_get/set_pl_deathsrn#include <amxmodx>rn#include <dodfun>rnrnnew killername[32] // declares a global array with 32 being the sizernnew player_melee_kills[32][1] // declares a global array with 32 being the size, the one makes an array inside an arrayrnrnpublic plugin_init() {rn // Registering plugin rn register_plugin("Melee Score Bonus","Version 0.1","The Tank")rn // Declaring CVARS rn register_cvar("scorebonus_enabled","1")rn register_cvar("scorebonus_changedeaths","2")rn register_cvar("scorebonus_changekills","2")rn register_cvar("amount_melee_attacks","4")rn}rnrn// Used to set that the client died TA=TK but used as a workaround for a bugrnpublic client_death(killer,victim,wpnindex,hitplace,TA) rn{rn rn // Checks if the CVAR and with that the plugin is enabledrn // the ==1 checks if its equal to one, a boolean 1/0 is by default truern // Checks if the client is indeed connected <- diamond opticrn if(get_cvar_num("scorebonus_enabled") == 1 && is_user_connected(killer))rn {rnrn // Checks if kill was a team killrn if(TA == 0)rn {rn // Declares an array called killername with 32 being size 0-31rn get_user_name(killer,killername,31) //gets the clients username, killer is var for player IDrnrn if(wpnindex == 1 || wpnindex == 2 || wpnindex == 19 || wpnindex == 34 || wpnindex == 37 || wpnindex == 38 || wpnindex == 39 || wpnindex == 41) //check with what weapon the kill was madern // Weapon index ID'srn // 1 = american knifern // 2 = german knifern // 19 = shovelrn // 34 = k98 bayonetrn // 37 = english knifern // 38 = garand buttrn // 39 = enfield bayonetrn // 41 = k43 buttrn {rn // if the kill was made by melee, checked above, then the melee_amount is +1rn player_melee_kills[killer][0] = player_melee_kills[killer][0] + 1rn // Once the amount of the array is equal to the amount given by the cvar then do the death and killsrn if(player_melee_kills[killer] == get_cvar_num("amount_melee_attacks"),1)rn { rn // sets clients deaths(id,getting players deaths(id) minus the deaths the cvar is set at, the 1 is for scoreboard refreshrn dod_set_pl_deaths(killer,dod_get_pl_deaths(killer) - get_cvar_num("scorebonus_changedeaths"),1)rn rn // If players deaths are less than 0 let's fix that ^_^rn if(dod_get_pl_deaths(killer) < 0) //is deaths smaller then 0, then...rn {rn dod_set_pl_deaths(killer,0,1) //sets deaths to(id, 0 deaths and the 1 is for scoreboard refreshrn }rn rn // sets clients kills(id, getting players kills(id) plus the kills the cvar is at, the 1 is for scoreboard refreshrn dod_set_user_frags(killer,dod_get_user_frags(killer),1) + get_cvar_num("scorebonus_changekills"),1)rn rn // the cvar is reached, the client got his score adjustment, time to reset his amount of melee attacksrn player_melee_kills[killer][0] = 0rn }rn }rn }rn }rn return PLUGIN_HANDLEDrn}rn// When the client disconnects the ID is also removed to be used by another playerrnpublic client_connect(killer)rn{rn player_melee_kills[id][0] = 0rn}rnrnThese are the errors shown in the compile logrnrn/home/groups/amxmodx/tmp3/phpnoq0aV.sma(63) : error 033: array must be indexed (variable "player_melee_kills")rn/home/groups/amxmodx/tmp3/phpnoq0aV.sma(75) : error 017: undefined symbol "dod_set_user_frags"rn/home/groups/amxmodx/tmp3/phpnoq0aV.sma(75) : error 029: invalid expression, assumed zerorn/home/groups/amxmodx/tmp3/phpnoq0aV.sma(75 -- 78) : warning 215: expression has no effectrn/home/groups/amxmodx/tmp3/phpnoq0aV.sma(88) : error 017: undefined symbol "id"rnrn4 Errors.rnCould not locate output file /home/groups/amxmodx/public_html/websc3/phpnoq0aV.amx (compile failed).rnrnrnreturn PLUGIN_HANDLED should that be added to:rnrnrn{rn player_melee_kills[id][0] = 0rn}rn
Threads: 15
Joined: Mar 2007
Everything is good besides some syntax stuff, a stray ",1" in an if statement, and the player id variable under client_connect. Here is the updated code:rnrn
//////////////////////////////////////////////////////////////////////////////////rn//rn// DoD Melee ScoreBonuesrn// - Version 0.1rn// - 01.07.2008rn//rn//////////////////////////////////////////////////////////////////////////////////rn//rn// Borrowed code from:rn// dod_meleebonus created by FireStorm, updated by Diamond-Opticrn// dod_scorereward created by FireStormrn//rn//////////////////////////////////////////////////////////////////////////////////rnrn// Modules being includedrn// <dodfun> needed at least for dod_get/set_pl_deathsrn#include <amxmodx>rn#include <dodfun>rnrnnew killername[32] // declares a global array with 32 being the sizernnew player_melee_kills[32][1] // declares a global array with 32 being the size, the one makes an array inside an arrayrnrnpublic plugin_init() {rn // Registering plugin rn register_plugin("Melee Score Bonus","Version 0.1","The Tank")rn // Declaring CVARS rn register_cvar("scorebonus_enabled","1")rn register_cvar("scorebonus_changedeaths","2")rn register_cvar("scorebonus_changekills","2")rn register_cvar("amount_melee_attacks","4")rn}rnrn// Used to set that the client died TA=TK but used as a workaround for a bugrnpublic client_death(killer,victim,wpnindex,hitplace,TA) rn{rn rn // Checks if the CVAR and with that the plugin is enabledrn // the ==1 checks if its equal to one, a boolean 1/0 is by default truern // Checks if the client is indeed connected <- diamond opticrn if(get_cvar_num("scorebonus_enabled") == 1 && is_user_connected(killer))rn {rnrn // Checks if kill was a team killrn if(TA == 0)rn {rn // Declares an array called killername with 32 being size 0-31rn get_user_name(killer,killername,31) //gets the clients username, killer is var for player IDrnrn if(wpnindex == 1 || wpnindex == 2 || wpnindex == 19 || wpnindex == 34 || wpnindex == 37 || wpnindex == 38 || wpnindex == 39 || wpnindex == 41) //check with what weapon the kill was madern // Weapon index ID'srn // 1 = american knifern // 2 = german knifern // 19 = shovelrn // 34 = k98 bayonetrn // 37 = english knifern // 38 = garand buttrn // 39 = enfield bayonetrn // 41 = k43 buttrn {rn // if the kill was made by melee, checked above, then the melee_amount is +1rn player_melee_kills[killer][0] = player_melee_kills[killer][0] + 1rn // Once the amount of the array is equal to the amount given by the cvar then do the death and killsrn if(player_melee_kills[killer][0] == get_cvar_num("amount_melee_attacks"))rn { rn // sets clients deaths(id,getting players deaths(id) minus the deaths the cvar is set at, the 1 is for scoreboard refreshrn dod_set_pl_deaths(killer,dod_get_pl_deaths(killer) - get_cvar_num("scorebonus_changedeaths"),1)rn rn // If players deaths are less than 0 let's fix that ^_^rn if(dod_get_pl_deaths(killer) < 0) //is deaths smaller then 0, then...rn {rn dod_set_pl_deaths(killer,0,1) //sets deaths to(id, 0 deaths and the 1 is for scoreboard refreshrn }rn rn // sets clients kills(id, getting players kills(id) plus the kills the cvar is at, the 1 is for scoreboard refreshrn dod_set_user_kills(killer,dod_get_user_kills(killer) + get_cvar_num("scorebonus_changekills"),1)rn rn // the cvar is reached, the client got his score adjustment, time to reset his amount of melee attacksrn player_melee_kills[killer][0] = 0rn }rn }rn }rn }rn return PLUGIN_HANDLEDrn}rn// When client connects, reset that id's melee kills so new player starts at 0rnpublic client_connect(id)rn{rn player_melee_kills[id][0] = 0rn}Threads: 59
Joined: Jan 2007
I have it running on my server now and get this error back in the logs. Any idea what this could be?rnrn
L 07/02/2008 - 02:07:23: [AMXX] Displaying debug trace (plugin "tank_melee_bonus.amxx")rnL 07/02/2008 - 02:07:23: [AMXX] Run time error 4: index out of bounds rnL 07/02/2008 - 02:07:23: [AMXX] [0] phpRSlOKf.sma::client_connect (line 88)rnrnOn line 88 the following is stated:rnrn// When client connects, reset that id's melee kills so new player starts at 0rnpublic client_connect(id)rn{rn player_melee_kills[id][0] = 0 //this is line 88rn}rnThreads: 15
Joined: Mar 2007
LOL I should thought of this when I looked at it but the way player ID's are it's 1-32 not 0-32 as the array works so all you have to do is change your array declaration to: player_melee_kills[33][1]
Threads: 59
Joined: Jan 2007
I changed it and tested it a while with a few guys from BAM and it didn't forward any error logs. Now I do have a question, I wanted to add a message to the player once their score has been changed with this plugin.rnrnI compiled it and it compiles just right, no errors but once I put it on my server I did not see any message coming up. Could someone point me what I did wrong?rnrn
client_print(0,print_chat,"[AMXX] %s changed his score (+2 k's, -2d's) with 4 melee kills!")rnset_hudmessage(36, 39, 192, -1.0, 0.9, 0, 6.0, 4.0, 0.1, 0.2, 4)rnshow_hudmessage(killer,"test")rnrnI was also kinda unsure how to read this syntax:rnrnshow_hudmessage ( index, message[], ... )rnrnThe index is set as killer, but how do you write down your message? And what does the ... stand for?Threads: 15
Joined: Mar 2007
The arguments required for show_hudmessage are (players id your sending message to, then the message it's self) You can even pass variables to the message which is what the ... is referring to like so:nshow_hudmessage(1,"I have %i kills",player_one_kills)nnYou will probably notice the the %i inside of the actual text being sent. This allows you to pass a certain type of data from a variable into the text. In this case it's an integer which is represented by %i. You can also use %s for string variables which is for text, and %f for floating point numbers. If you pass multiple variables into the text they go in sequential order like so:nshow_hudmessage(1,"I have %i kills and %i deaths",player_one_kills,player_one_deaths)nnWhat you have there should work though. Where did you place it in your code?
Threads: 15
Joined: Mar 2007
Almost forgot, the
client_print(0,print_chat,"[AMXX] %s changed his score (+2 k's, -2d's) with 4 melee kills!")rnrnline needs some additional information for the players name. What you want is new temp_player_name[33]rnget_user_name(killer,temp_player_name,32)rnclient_print(0,print_chat,"[AMXX] %s changed his score (+2 k's, -2d's) with 4 melee kills!",temp_player_name)rn As you can see this works just like the hud_message where you can pass in variables. You will find this to be the same with several amxmodx functions. In this case though since the player's name is text, we use %s.
