AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_user_frags, read_argv (https://forums.alliedmods.net/showthread.php?t=223723)

Gasior 08-16-2013 12:20

get_user_frags, read_argv
 
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")



akcaliberg 08-16-2013 12:30

Re: get_user_frags, read_argv
 
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.

Gasior 08-16-2013 14:19

Re: get_user_frags, read_argv
 
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 08-18-2013 05:18

Re: get_user_frags, read_argv
 
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?

akcaliberg 08-18-2013 12:49

Re: get_user_frags, read_argv
 
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 )



tonykaram1993 08-18-2013 13:16

Re: get_user_frags, read_argv
 
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.

Gasior 08-18-2013 16:49

Re: get_user_frags, read_argv
 
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.

ConnorMcLeod 08-19-2013 00:45

Re: get_user_frags, read_argv
 
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);



akcaliberg 08-19-2013 05:54

Re: get_user_frags, read_argv
 
it's good to know :D thanks connor.


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

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