Raised This Month: $ Target: $400
 0% 

Arguments not finishing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
slmclarengt
Veteran Member
Join Date: Jul 2004
Location: The Cookie Jar... or Pul
Old 02-16-2007 , 21:17   Arguments not finishing
Reply With Quote #1

Sorry for the name, It's very hard to make into a topic name.

My goal for this plugin: To allow players to transfer Experience (XP) between themselves but only allow a percentage of transferable XP.

Example: Player A has 10,000 XP and wants to give player B 100 XP. Percentage of usable XP is 10% so Player A transfers 10,000 XP so that player B receives the 100 XP.

My problem(s): When a name is passed via "/transferxp <name> <amount>" the plugin does not do anything, but when NOTHING is called but saying "/transferxp" it gives all the debug statements I included in the code. Here is a picture for better reference of all info. shown from JUST typing "/transferxp": [IMG]http://img126.**************/img126/4367/csitaly0000fv9.th.png[/IMG]

Note: the info. you cannot see is that of my debug statements inside the code. It says the SERVER is receiving the XP when I provide NO parameters.

My idea: For player A (Bill) to give XP to player B (John) by typing
"/transferxp John 10000" using the regular "say" function.

My code:
Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Transfer XP (WC3FT)"
#define VERSION ".4a"
#define AUTHOR "slmclarengt"

new xp_percent;

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_clcmd("say /transferxp", "transfer_xp", 0, "<name> <XP to transfer> - transfers xp between players/races")
	register_clcmd("say_team /transferxp", "transfer_xp", 0, "<name> <XP to transfer> - transfers xp between players/races")
	xp_percent = register_cvar("amx_xp_percent", "10")// XP actually used, other xp trashed (default: 10)
}

public transfer_xp(id)
{
	if (read_argc() == 1) // only 1 parameter (nothing passed)
	{
		client_print(id, print_chat, "Usage: /transferxp <name> <Amount XP to transfer>", get_pcvar_num(xp_percent));
	}
	new target[32], amt[10];
	
	read_argv(1, target, 31) // receiver of xp
	read_argv(2, amt, 9) // amount of xp
	
	client_print(0, print_chat, "Debug 1: Target's ID # %d - Amount: %d", target, amt); //debug
	new xp = str_to_num(amt); // make string to number for multiplication
	client_print(0, print_chat, "Debug 2: %s wants to give a player %d XP", target, xp); //debug
	new target_num = str_to_num(target);
	new target_id = get_user_index("target_num"); //Index for target
	client_print(0, print_chat,"Debug 3: %d is the receivers ID", target_id); //debug
	
	new negative_xp = (0 - xp); // negative xp to take from giver
	new t_xp = (xp * (get_pcvar_num(xp_percent) / 100));// ACTUAL transfer xp amount (amt * percent kept)
	
	client_print(0, print_chat, "%d XP will be taken from giver & %d XP will be given to receiver", negative_xp, t_xp)
	
	new receive_name[32];
	get_user_name(target_id, receive_name, 31);
	new give_name[32];
	get_user_name(id, give_name, 31);
	
	client_print(id, print_chat, "You are giving %d XP but losing %d XP to %s - what a nice person!", t_xp, xp, receive_name)
	client_print(target_id, print_chat, "%s is giving you %d XP for the current race - be thankful!", give_name, t_xp)
	
	server_cmd("amx_givexp %s %d", receive_name, t_xp) // give t_xp XP to receiver
	server_cmd("amx_givexp %s %d", give_name, negative_xp); // take XP away from giver
}
Also attached. A fix for this to work will result in major karma and possibly other rewards

Slmclarengt
Attached Files
File Type: sma Get Plugin or Get Source (Transfer_XP.sma - 460 views - 2.2 KB)
__________________
But we don’t beat the Reaper by living longer. We beat the Reaper by living well. -Dr. Randy Pausch, R.I.P.

Come play WC3:FT on BnD Clan Server! You know you want to: Connect to WC3:FT BnD - go ahead click me!
slmclarengt is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 02-16-2007 , 21:50   Re: Arguments not finishing
Reply With Quote #2

I rewrote it since your code is basically unworkable (at least to me). There's no real way to detect 10% of their XP, so I just left that part out:

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     register_plugin("Give XP","1.0","Hawk552")         register_clcmd("say","CmdSay") } public CmdSay(id) {     static Args[6][33],Name[33]     new Num = read_argc()     for(new Count = 1;Count <= Num;Count++)         read_argv(Count,Args[Count - 1],32)         if(!equali(Args[0],"/transferxp"))         return         new XP = str_to_num(Args[Num - 1])     if(XP < 1)     {         client_print(id,print_chat,"[WAR3FT] You must give more than 0 XP (entered %d)",XP)         return     }         for(new Count = 1,Len;Count <= Num - 2;Count++)         Len += copy(Name[Len],32 - Len,Args[Count])         new Target = cmd_target(id,Name,0)     if(!Target || !is_user_connected(Target))     {         client_print(id,print_chat,"[WAR3FT] Could not find a user matching your input")         return     }         get_user_name(id,Name,32)     static tName[33]     get_user_name(Target,Name,32)         client_print(0,print_chat,"[WAR3FT] %s is giving %s %d XP",Name,tName,XP)         server_cmd("amx_givexp ^"%s^" %d",tName,XP)     server_cmd("amx_givexp ^"%s^" -%d",Name,XP) }

Problems:
1) You can give more XP than you have.
2) You can't cap it at 10% (as I said before).

This is more an example than anything - you could integrate it into your WC3 plugin (I'm guessing FT) to give the ability to check the XP of these players.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Zenith77
Veteran Member
Join Date: Aug 2005
Old 02-16-2007 , 22:21   Re: Arguments not finishing
Reply With Quote #3

How can you not get 10 percent of a number? There are plenty of ways...

One being:
Code:
// Assuming you're var is a cell and needs converting: new Float:maxAmount = float(var) * 0.10; // 10 percent :o. if (xpToTransfer > _:maxAmount) {      new takeAway = xpToTransfer - _:maxAmount;      new amount = xpToTransfer - takeAway;      // ta da }

(My math may be a little off [and code for that matter], I'm half asleep :-) )
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred

Last edited by Zenith77; 02-16-2007 at 22:26.
Zenith77 is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 02-16-2007 , 22:23   Re: Arguments not finishing
Reply With Quote #4

Quote:
Originally Posted by Zenith77 View Post
How can you not get 10 percent of a number? There is plenty of ways...

One being:
Code:
// Assuming you're var is a cell and needs converting: new Float:maxAmount = float(var) * 0.10; // 10 percent . if (xpToTransfer > maxAmount) // :dmfkdnk!
Idiot, I meant you can't get the ORIGINAL, screw 10%.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Zenith77
Veteran Member
Join Date: Aug 2005
Old 02-16-2007 , 22:30   Re: Arguments not finishing
Reply With Quote #5

'scuse me :p.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
slmclarengt
Veteran Member
Join Date: Jul 2004
Location: The Cookie Jar... or Pul
Old 02-17-2007 , 22:58   Re: Arguments not finishing
Reply With Quote #6

Quote:
Originally Posted by Hawk552 View Post
I rewrote it since your code is basically unworkable (at least to me). There's no real way to detect 10% of their XP, so I just left that part out:

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     register_plugin("Give XP","1.0","Hawk552")         register_clcmd("say","CmdSay") } public CmdSay(id) {     static Args[6][33],Name[33]     new Num = read_argc()     for(new Count = 1;Count <= Num;Count++)         read_argv(Count,Args[Count - 1],32)         if(!equali(Args[0],"/transferxp"))         return         new XP = str_to_num(Args[Num - 1])     if(XP < 1)     {         client_print(id,print_chat,"[WAR3FT] You must give more than 0 XP (entered %d)",XP)         return     }         for(new Count = 1,Len;Count <= Num - 2;Count++)         Len += copy(Name[Len],32 - Len,Args[Count])         new Target = cmd_target(id,Name,0)     if(!Target || !is_user_connected(Target))     {         client_print(id,print_chat,"[WAR3FT] Could not find a user matching your input")         return     }         get_user_name(id,Name,32)     static tName[33]     get_user_name(Target,Name,32)         client_print(0,print_chat,"[WAR3FT] %s is giving %s %d XP",Name,tName,XP)         server_cmd("amx_givexp ^"%s^" %d",tName,XP)     server_cmd("amx_givexp ^"%s^" -%d",Name,XP) }

Problems:
1) You can give more XP than you have.
2) You can't cap it at 10% (as I said before).

This is more an example than anything - you could integrate it into your WC3 plugin (I'm guessing FT) to give the ability to check the XP of these players.
Ok, your code definitely uses more optimization and proper coding technique than mine because you practice more, therefore, you write better. Regarding the 10%, I'm trying to take 10% of whatever they input later on in the code like right before the "amx_givexp" line so couldn't we insert a line to take 90% of the XP away and give the target only 10%? I think it would be MAJORLY abused on a server if you could just transfer XP between everyone that simply without any kind of consequence. It's like taking out a loan and only having to pay the loan back, no interest/APR.

Slmclarengt
__________________
But we don’t beat the Reaper by living longer. We beat the Reaper by living well. -Dr. Randy Pausch, R.I.P.

Come play WC3:FT on BnD Clan Server! You know you want to: Connect to WC3:FT BnD - go ahead click me!
slmclarengt is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 02-18-2007 , 09:04   Re: Arguments not finishing
Reply With Quote #7

Well I'm saying that there's no way to extract the amount of XP someone has from WC3FT, thus you cannot derive 10% of their XP.

If you want to modify the WC3FT source code itself, it would be pretty easy (I think there's a global variable called g_PlayerXP or something like that).
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
slmclarengt
Veteran Member
Join Date: Jul 2004
Location: The Cookie Jar... or Pul
Old 02-18-2007 , 14:10   Re: Arguments not finishing
Reply With Quote #8

Ok, I'm saying take 10% of the TRANSFERRED XP so 10% of 100 XP to TRANSFER would be 10. Also, this plugin does not work :-). I was testing it on my server and if any arguments are passed (to transfer xp), the xp does not do anything, but the part of code that catches when no arguments are passed works fine. It does give the "You must transfer more than 0 xp (entered 0)" if I just type "/transferxp" without any arguments, but if I type "/transferxp hawk552 2000" it does nothing and says nothing.

Slmclarengt
__________________
But we don’t beat the Reaper by living longer. We beat the Reaper by living well. -Dr. Randy Pausch, R.I.P.

Come play WC3:FT on BnD Clan Server! You know you want to: Connect to WC3:FT BnD - go ahead click me!
slmclarengt is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 02-18-2007 , 14:19   Re: Arguments not finishing
Reply With Quote #9

Try simplifying it into 3 args instead of the 6 that I did, it's just in case your name is like "bob bill smith" and the person types each one without quotes.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
slmclarengt
Veteran Member
Join Date: Jul 2004
Location: The Cookie Jar... or Pul
Old 02-20-2007 , 18:05   Re: Arguments not finishing
Reply With Quote #10

Quote:
Originally Posted by Hawk552 View Post
Try simplifying it into 3 args instead of the 6 that I did, it's just in case your name is like "bob bill smith" and the person types each one without quotes.
Still does not work. No MATTER WHAT is typed, it tells them they entered 0 XP. Whether they say "hello" or "/transferxp" it does not matter, it automatically responds "You have entered 0 xp..." - Here's the code.

Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
    register_plugin("Give XP","1.0","Hawk552")
    
    register_clcmd("say","CmdSay")
}

public CmdSay(id)
{
    static Args[3][33],Name[33]
    new Num = read_argc()
    for(new Count = 1;Count <= Num;Count++)
        read_argv(Count,Args[Count - 1],32)

    new XP = str_to_num(Args[Num - 1])
    if(XP < 1)
    {
        client_print(id,print_chat,"[WAR3FT] You must give more than 0 XP (entered %d)",XP)
        return
    }
    
    for(new Count = 1,Len;Count <= Num - 2;Count++)
        Len += copy(Name[Len],32 - Len,Args[Count])
    
    new Target = cmd_target(id,Name,0)
    if(!Target || !is_user_connected(Target))
    {
        client_print(id,print_chat,"[WAR3FT] Could not find a user matching your input")
        return
    }
    
    get_user_name(id,Name,32)
    static tName[33]
    get_user_name(Target,Name,32)
    
    client_print(0,print_chat,"[WAR3FT] %s is giving %s %d XP",Name,tName,XP)
    
    server_cmd("amx_givexp ^"%s^" %d",tName,XP)
    server_cmd("amx_givexp ^"%s^" -%d",Name,XP)
}
Slmclarengt
__________________
But we don’t beat the Reaper by living longer. We beat the Reaper by living well. -Dr. Randy Pausch, R.I.P.

Come play WC3:FT on BnD Clan Server! You know you want to: Connect to WC3:FT BnD - go ahead click me!
slmclarengt is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode