Raised This Month: $ Target: $400
 0% 

get_user_frags, read_argv


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gasior
Member
Join Date: Mar 2012
Old 08-16-2013 , 12:20   get_user_frags, read_argv
Reply With Quote #1

Hi,
I would like my plugin to read get_user_frags(id) and use it to set_user_deaths. It suppose to swap frags with deaths. I tried to work it out from this plugin but I just can't use read_argv
PHP Code:
/* 

*   Change Score 
*   Version 2.0.5 
*   Author: Freecode;   [email protected] (MSN)  FCunnClan (AIM) 

*   This plugin will will change persons Frags and Deaths.

*   Requirements: 
*      AMXX 1.55  

*   Admin Commands: 
*      amx_chscore <nick/@CT/@TERRORIST> <frags #> <deaths #>

*   To Do:  
*      Nothing :)

*/ 
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
new gmsgScoreInfo
 

public chscore(id,level,cid)
{
    if (!
cmd_access(id,level,cid,2)) 
    { 
      return 
PLUGIN_HANDLED 
    
}
    new 
victim[32],deathsI[32],fragsI[32]
    
read_argv(1,victim,31)

    
read_argv(2,fragsI,31
    new 
frags str_to_num(fragsI
       
    
read_argv(3,deathsI,31
    new 
deaths str_to_num(deathsI
    
    if (
victim[0]=='@')
    { 
        new 
team[32], inum 
        get_players
(team,inum,"e",victim[1]) 
        if (
inum==0)
        { 
            
console_print(id,"[AMX] No clients found on such team."
            return 
PLUGIN_HANDLED 
        

        for (new 
i=0;i<inum;++i)
        {
            new 
teams get_user_team(team[i])  
            
set_user_frags(team[i],frags)
            
cs_set_user_deaths(team[i],deaths)
            
message_begin(MSG_ALL,gmsgScoreInfo)
            
write_byteteam[i] )  
            
write_short(frags
            
write_short(deaths
            
write_short(0
            
write_short(teams
            
message_end() 
        } 
    } 
    else
    {
        new 
user cmd_target(id,victim,0)
        new 
authid[32]
        
get_user_authid(user,authid,31)  
        if (!
user)
        {
            
console_print(id,"[AMX] No such client found."
            return 
PLUGIN_HANDLED 
        
}
        new 
teams get_user_team(user)
        
set_user_frags(user,frags)
        
cs_set_user_deaths(user,deaths)
        
message_begin(MSG_ALL,gmsgScoreInfo
          
write_byte(user
          
write_short(frags
          
write_short(deaths
          
write_short(0
          
write_short(teams
          
message_end()
      }
    return 
PLUGIN_HANDLED 


public 
plugin_init()
{
    
register_plugin("Change Score","2.0.5","Freecode")
    
register_clcmd("amx_chscore","chscore",ADMIN_CVAR," - amx_chscore <nick/@CT/@TERRORIST> <frags #> <deaths #>")
    
gmsgScoreInfo get_user_msgid("ScoreInfo")

Gasior is offline
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 08-16-2013 , 12:30   Re: get_user_frags, read_argv
Reply With Quote #2

PHP Code:
if (!cmd_access(id,level,cid,2)) 
->

PHP Code:
if (!cmd_access(id,level,cid,4)) 
you shouldn't copy-paste something, you should learn it.

Last edited by akcaliberg; 08-16-2013 at 12:31.
akcaliberg is offline
Gasior
Member
Join Date: Mar 2012
Old 08-16-2013 , 14:19   Re: get_user_frags, read_argv
Reply With Quote #3

The best way for me to learn is to compare one plugin with another.

But as long as you understand this code, could you comment lines which does what? It would be really easier for me to see how it works.
Gasior is offline
Old 08-16-2013, 15:33
akcaliberg
This message has been deleted by akcaliberg.
Gasior
Member
Join Date: Mar 2012
Old 08-18-2013 , 05:18   Re: get_user_frags, read_argv
Reply With Quote #5

PHP Code:
        case 12:
        {
            
ColorChat(id,RED,"^3[FUNSHOP]^4 You draw^3 swap frags with deaths^4"0)
            
cs_set_user_deaths(idget_user_frags(id) )
            
set_user_frags(idget_user_deaths(id) )
        } 
So the problem is that when I try to change frags, the number of deaths is already equal to frags.
I need to save the number of frags before I start case 12. Anyone wants to help?

Last edited by Gasior; 08-18-2013 at 08:37.
Gasior is offline
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 08-18-2013 , 12:49   Re: get_user_frags, read_argv
Reply With Quote #6

PHP Code:
case 12:
{
    
ColorChat(id,RED,"^3[FUNSHOP]^4 You draw^3 swap frags with deaths^4"0)
    new 
temp get_user_deaths(id)
    
cs_set_user_deaths(idget_user_frags(id) )
    
set_user_frags(idtemp )

akcaliberg is offline
tonykaram1993
Senior Member
Join Date: Mar 2013
Location: This World
Old 08-18-2013 , 13:16   Re: get_user_frags, read_argv
Reply With Quote #7

Yes what akcaliberg made is the correct way. The way you have done it like so
PHP Code:
case 12:
        {
            
ColorChat(id,RED,"^3[FUNSHOP]^4 You draw^3 swap frags with deaths^4"0)
            
cs_set_user_deaths(idget_user_frags(id) )
            
set_user_frags(idget_user_deaths(id) )
        } 
will not work. Why? Here is a quick scenario. I have 25 frags and 8 deaths. When you use cs_set_user_deaths( id, get_user_frags( id ) ), you changed the deaths to 25, so now I have 25 frags and 25 deaths. Then you use set_user_frags( id, get_user_deaths( id ) ), so since my frags are 25 (which is equal to the amount of deaths, it is exactly like doing nothing.

But in contrast to the way akcaliberg did, you save the amount of deaths, and then change it. And when you want to change the amount of frags, you use the saved value in the variable 'temp', and all goes well.
__________________
My Plugins:
UltimatePlugin
UltimateSurf
UltimateAdmin
Code:
rcon version | rcon amxx version | rcon meta version
rcon amxx plugins | rcon meta list | rcon status
I AM INACTIVE ON THIS FORUM - For direct contact: [email protected]
tonykaram1993 is offline
Gasior
Member
Join Date: Mar 2012
Old 08-18-2013 , 16:49   Re: get_user_frags, read_argv
Reply With Quote #8

Quote:
So the problem is that when I try to change frags, the number of deaths is already equal to frags.
I need to save the number of frags before I start case 12. Anyone wants to help?
I knew what was the problem I just couldn't handle it. Thanks, akcaliberg.

Last edited by Gasior; 08-18-2013 at 16:57.
Gasior is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-19-2013 , 00:45   Re: get_user_frags, read_argv
Reply With Quote #9

Little fix to make things better :

Yu have to use cs_set_user_deaths AFTER set_user_frags, because only cs_set_user_deaths is updating scoreboard, so if you send cs_set_user_deaths first, you gonna see a wrong value (same deaths as frags) even if frags gonna be changed right after.

PHP Code:
SwapDeathFrags(id)
{
    new 
frags get_user_frags(id);
    
set_user_frags(idcs_get_user_deaths(id));
    
cs_set_user_deaths(idfrags);

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 08-19-2013 , 05:54   Re: get_user_frags, read_argv
Reply With Quote #10

it's good to know thanks connor.
akcaliberg is offline
Reply


Thread Tools
Display Modes

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:49.


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