Raised This Month: $32 Target: $400
 8% 

Selam


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Erra
Member
Join Date: Jun 2021
Old 10-25-2021 , 13:56   Selam
Reply With Quote #1

Greetings, you can make this plugin time-based so that it can be used once every 20 minutes.

Code:
#include <amxmodx>
#include <amxmisc>
#include <cromchat>
#include <cstrike>
#include <crxranks>

#define PLUGIN "Points Donate"
#define VERSION "1.0"
#define AUTOR "iceeedR"

#if defined client_disconnected
    #define client_disconnect client_disconnected
#endif

#if !defined MAX_PLAYERS
const MAX_PLAYERS = 32
#endif

/* Edit by OciXCrom: made the plugin donate points from Custom Shop instead of money */

new const Prefix[] = "REALTR"
new DonateTarget[MAX_PLAYERS +1]

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTOR);
    register_clcmd("say /paylas", "DonateCmd")
    register_clcmd("plugin_donate", "DonateHandler")
}

public client_disconnect(id)
{
    DonateTarget[id] = 1 // just for secure
}

public DonateCmd(id)
{
    new szItem[64]
    formatex(szItem, charsmax(szItem), "\y[\w%s\d - \rAKTARMA MENU \y ]", Prefix)

    new iMenu = menu_create(szItem, "donate_handler")

    new iPlayers[MAX_PLAYERS], iNum
    get_players(iPlayers, iNum, "e", (cs_get_user_team(id) == CS_TEAM_T) ? "TERRORIST" : "CT")
    for(new i, szTempid[10], iPlayer;i < iNum;i++)
    {
        iPlayer = iPlayers[i]

        if(iPlayer != id)
        {
            num_to_str(iPlayer, szTempid, charsmax(szTempid))
            get_user_name(iPlayer, szItem, charsmax(szItem))
            menu_additem(iMenu, szItem, szTempid)
        }
    }

    menu_display(id, iMenu)
    return PLUGIN_HANDLED
}

public donate_handler(id, iMenu, iItem)
{
    if(iItem == MENU_EXIT)
    {
        menu_destroy(iMenu)
        return PLUGIN_HANDLED
    }
    new iData[6], szItemName[MAX_PLAYERS * 2], iAccess, iCallback
    menu_item_getinfo(iMenu, iItem, iAccess, iData, charsmax(iData), szItemName, charsmax(szItemName), iCallback)

    DonateTarget[id] = str_to_num(iData)

    if(!DonateTarget[id])
    {
        client_print_color(id, print_team_default, "%s Bu oyuncu mevcut değil.", Prefix)
        menu_display(id, iMenu)
        DonateTarget[id] = 0
        return PLUGIN_HANDLED
    }

    client_cmd(id, "messagemode plugin_donate")

    client_print_color(id, print_team_default, "%s Ne kadar vermek istediğinizi yazin.", Prefix)
    return PLUGIN_HANDLED
}

public DonateHandler(id)
{
    new szValue[8]
    read_argv(1, szValue, charsmax(szValue))

    new iValue = str_to_num(szValue)

    new iPlayerXP = crxranks_get_user_xp(id)

    if( iPlayerXP < iValue || iValue <= 0)
    {
        client_print_color(id, print_team_default, "%s Yeterli XP'niz yok.", Prefix)
        return PLUGIN_CONTINUE
    }
	
    crxranks_give_user_xp( DonateTarget[id], iValue)
    crxranks_give_user_xp( id, iValue * -1)

    new szNameGiver[MAX_PLAYERS]
    get_user_name( id, szNameGiver, charsmax( szNameGiver))

    new szNameReceiver[MAX_PLAYERS]
    get_user_name(DonateTarget[id], szNameReceiver, charsmax(szNameReceiver))

    new iPlayers[MAX_PLAYERS], iNum
    get_players(iPlayers, iNum, "e", (cs_get_user_team(id) == CS_TEAM_T) ? "TERRORIST" : "CT")
    for(new i;i < iNum;i++)
    {
        client_print_color(iPlayers[i], print_team_default, "%s^x04 %s^x01 aktardi^x04 $%i^x01 EXP^x04 %s.", Prefix, szNameGiver, iValue, szNameReceiver)
    }
    client_cmd(DonateTarget[id], "spk ^"items/9mmclip1.wav^"")

    DonateTarget[id] = 0
    return PLUGIN_HANDLED
}
Erra is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-25-2021 , 23:33   Re: Selam
Reply With Quote #2

This should work for you. You'll probably want to change the language of the message that is shown when they try to open the menu and aren't allowed to use it yet to make it consistent with the other messages.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cromchat>
#include <cstrike>
#include <crxranks>

#define PLUGIN "Points Donate"
#define VERSION "1.0"
#define AUTOR "iceeedR"

#if defined client_disconnected
    #define client_disconnect client_disconnected
#endif

#if !defined MAX_PLAYERS
const MAX_PLAYERS 32
#endif

/* Edit by OciXCrom: made the plugin donate points from Custom Shop instead of money */

new const Prefix[] = "REALTR"
new DonateTarget[MAX_PLAYERS +1]
new 
LastDonationTime[MAX_PLAYERS+1]
new const 
DONATION_INTERVAL 20 60 // Donation interval in seconds

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTOR);
    
register_clcmd("say /paylas""DonateCmd")
    
register_clcmd("plugin_donate""DonateHandler")
}

public 
client_disconnect(id)
{
    
DonateTarget[id] = // just for secure
    
LastDonationTime[id] = 0
}

public 
DonateCmd(id)
{
    if( 
get_systime() < (LastDonationTime[id] + DONATION_INTERVAL) )
    {
        
client_print(idprint_chat"You must wait %d minutes between donations"DONATION_INTERVAL 60)
        return 
PLUGIN_HANDLED
    
}

    new 
szItem[64]
    
formatex(szItemcharsmax(szItem), "\y[\w%s\d - \rAKTARMA MENU \y ]"Prefix)

    new 
iMenu menu_create(szItem"donate_handler")

    new 
iPlayers[MAX_PLAYERS], iNum
    get_players
(iPlayersiNum"e", (cs_get_user_team(id) == CS_TEAM_T) ? "TERRORIST" "CT")
    for(new 
iszTempid[10], iPlayer;iNum;i++)
    {
        
iPlayer iPlayers[i]

        if(
iPlayer != id)
        {
            
num_to_str(iPlayerszTempidcharsmax(szTempid))
            
get_user_name(iPlayerszItemcharsmax(szItem))
            
menu_additem(iMenuszItemszTempid)
        }
    }

    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
donate_handler(idiMenuiItem)
{
    if(
iItem == MENU_EXIT)
    {
        
menu_destroy(iMenu)
        return 
PLUGIN_HANDLED
    
}
    new 
iData[6], szItemName[MAX_PLAYERS 2], iAccessiCallback
    menu_item_getinfo
(iMenuiItemiAccessiDatacharsmax(iData), szItemNamecharsmax(szItemName), iCallback)

    
DonateTarget[id] = str_to_num(iData)

    if(!
DonateTarget[id])
    {
        
client_print_color(idprint_team_default"%s Bu oyuncu mevcut değil."Prefix)
        
menu_display(idiMenu)
        
DonateTarget[id] = 0
        
return PLUGIN_HANDLED
    
}

    
client_cmd(id"messagemode plugin_donate")

    
client_print_color(idprint_team_default"%s Ne kadar vermek istediğinizi yazin."Prefix)
    return 
PLUGIN_HANDLED
}

public 
DonateHandler(id)
{
    if( 
get_systime() < (LastDonationTime[id] + DONATION_INTERVAL) )
    {
        return 
PLUGIN_HANDLED
    
}
    
    new 
szValue[8]
    
read_argv(1szValuecharsmax(szValue))

    new 
iValue str_to_num(szValue)
    
iValue = (iValue 10000 10000 iValue)

    new 
iPlayerXP crxranks_get_user_xp(id)

    if( 
iPlayerXP iValue || iValue <= 0)
    {
        
client_print_color(idprint_team_default"%s Yeterli XP'niz yok."Prefix)
        return 
PLUGIN_CONTINUE
    
}
    
    
crxranks_give_user_xpDonateTarget[id], iValue)
    
crxranks_give_user_xpidiValue * -1)

    new 
szNameGiver[MAX_PLAYERS]
    
get_user_nameidszNameGivercharsmaxszNameGiver))

    new 
szNameReceiver[MAX_PLAYERS]
    
get_user_name(DonateTarget[id], szNameReceivercharsmax(szNameReceiver))

    new 
iPlayers[MAX_PLAYERS], iNum
    get_players
(iPlayersiNum"e", (cs_get_user_team(id) == CS_TEAM_T) ? "TERRORIST" "CT")
    for(new 
i;iNum;i++)
    {
        
client_print_color(iPlayers[i], print_team_default"%s^x04 %s^x01 aktardi^x04 $%i^x01 EXP^x04 %s."PrefixszNameGiveriValueszNameReceiver)
    }
    
client_cmd(DonateTarget[id], "spk ^"items/9mmclip1.wav^"")

    
DonateTarget[id] = 0
    
    LastDonationTime
[id] = get_systime()
    
    return 
PLUGIN_HANDLED

Note that I can't compile it because I don't have those includes handy but I think I've done it all correctly.
__________________

Last edited by fysiks; 11-01-2021 at 22:30. Reason: added 10,000 limit
fysiks is offline
Erra
Member
Join Date: Jun 2021
Old 10-27-2021 , 09:02   Re: Selam
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
This should work for you. You'll probably want to change the language of the message that is shown when they try to open the menu and aren't allowed to use it yet to make it consistent with the other messages.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cromchat>
#include <cstrike>
#include <crxranks>

#define PLUGIN "Points Donate"
#define VERSION "1.0"
#define AUTOR "iceeedR"

#if defined client_disconnected
    #define client_disconnect client_disconnected
#endif

#if !defined MAX_PLAYERS
const MAX_PLAYERS 32
#endif

/* Edit by OciXCrom: made the plugin donate points from Custom Shop instead of money */

new const Prefix[] = "REALTR"
new DonateTarget[MAX_PLAYERS +1]
new 
LastDonationTime[MAX_PLAYERS+1]
new const 
DONATION_INTERVAL 20 60 // Donation interval in seconds

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTOR);
    
register_clcmd("say /paylas""DonateCmd")
    
register_clcmd("plugin_donate""DonateHandler")
}

public 
client_disconnect(id)
{
    
DonateTarget[id] = // just for secure
    
LastDonationTime[id] = 0
}

public 
DonateCmd(id)
{
    if( 
get_systime() < (LastDonationTime[id] + DONATION_INTERVAL) )
    {
        
client_print(idprint_chat"You must wait %d minutes between donations"DONATION_INTERVAL 60)
        return 
PLUGIN_HANDLED
    
}

    new 
szItem[64]
    
formatex(szItemcharsmax(szItem), "\y[\w%s\d - \rAKTARMA MENU \y ]"Prefix)

    new 
iMenu menu_create(szItem"donate_handler")

    new 
iPlayers[MAX_PLAYERS], iNum
    get_players
(iPlayersiNum"e", (cs_get_user_team(id) == CS_TEAM_T) ? "TERRORIST" "CT")
    for(new 
iszTempid[10], iPlayer;iNum;i++)
    {
        
iPlayer iPlayers[i]

        if(
iPlayer != id)
        {
            
num_to_str(iPlayerszTempidcharsmax(szTempid))
            
get_user_name(iPlayerszItemcharsmax(szItem))
            
menu_additem(iMenuszItemszTempid)
        }
    }

    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
donate_handler(idiMenuiItem)
{
    if(
iItem == MENU_EXIT)
    {
        
menu_destroy(iMenu)
        return 
PLUGIN_HANDLED
    
}
    new 
iData[6], szItemName[MAX_PLAYERS 2], iAccessiCallback
    menu_item_getinfo
(iMenuiItemiAccessiDatacharsmax(iData), szItemNamecharsmax(szItemName), iCallback)

    
DonateTarget[id] = str_to_num(iData)

    if(!
DonateTarget[id])
    {
        
client_print_color(idprint_team_default"%s Bu oyuncu mevcut değil."Prefix)
        
menu_display(idiMenu)
        
DonateTarget[id] = 0
        
return PLUGIN_HANDLED
    
}

    
client_cmd(id"messagemode plugin_donate")

    
client_print_color(idprint_team_default"%s Ne kadar vermek istediğinizi yazin."Prefix)
    return 
PLUGIN_HANDLED
}

public 
DonateHandler(id)
{
    if( 
get_systime() < (LastDonationTime[id] + DONATION_INTERVAL) )
    {
        return 
PLUGIN_HANDLED
    
}
    
    new 
szValue[8]
    
read_argv(1szValuecharsmax(szValue))

    new 
iValue str_to_num(szValue)

    new 
iPlayerXP crxranks_get_user_xp(id)

    if( 
iPlayerXP iValue || iValue <= 0)
    {
        
client_print_color(idprint_team_default"%s Yeterli XP'niz yok."Prefix)
        return 
PLUGIN_CONTINUE
    
}
    
    
crxranks_give_user_xpDonateTarget[id], iValue)
    
crxranks_give_user_xpidiValue * -1)

    new 
szNameGiver[MAX_PLAYERS]
    
get_user_nameidszNameGivercharsmaxszNameGiver))

    new 
szNameReceiver[MAX_PLAYERS]
    
get_user_name(DonateTarget[id], szNameReceivercharsmax(szNameReceiver))

    new 
iPlayers[MAX_PLAYERS], iNum
    get_players
(iPlayersiNum"e", (cs_get_user_team(id) == CS_TEAM_T) ? "TERRORIST" "CT")
    for(new 
i;iNum;i++)
    {
        
client_print_color(iPlayers[i], print_team_default"%s^x04 %s^x01 aktardi^x04 $%i^x01 EXP^x04 %s."PrefixszNameGiveriValueszNameReceiver)
    }
    
client_cmd(DonateTarget[id], "spk ^"items/9mmclip1.wav^"")

    
DonateTarget[id] = 0
    
    LastDonationTime
[id] = get_systime()
    
    return 
PLUGIN_HANDLED

Note that I can't compile it because I don't have those includes handy but I think I've done it all correctly.
thank you very much sir, my last request is to send only 10 thousand exp at one time, is this possible?
Erra is offline
Erra
Member
Join Date: Jun 2021
Old 10-29-2021 , 23:19   Re: Selam
Reply With Quote #4

is it possible ?
Erra is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-31-2021 , 18:33   Re: Selam
Reply With Quote #5

The quickest way is to add

Code:
iValue = (iValue > 10000 ? 10000 : iValue)
immediately after

Code:
new iValue = str_to_num(szValue)
giving:

Code:
	new iValue = str_to_num(szValue)
	iValue = (iValue > 10000 ? 10000 : iValue)
__________________
fysiks is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 10-31-2021 , 23:54   Re: Selam
Reply With Quote #6

I don't even remember writing this plugin, but here's a small fix for the value of DonateTarget[id] which must be -1 under certain circumstances and not 1 or 0.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cromchat>
#include <cstrike>
#include <crxranks>

#define PLUGIN "Points Donate"
#define VERSION "1.0"
#define AUTOR "iceeedR"

#if defined client_disconnected
    #define client_disconnect client_disconnected
#endif

#if !defined MAX_PLAYERS
const MAX_PLAYERS 32
#endif

/* Edit by OciXCrom: made the plugin donate points from Custom Shop instead of money */

new const Prefix[] = "REALTR"
new DonateTarget[MAX_PLAYERS +1]
new 
LastDonationTime[MAX_PLAYERS+1]
new const 
DONATION_INTERVAL 20 60 // Donation interval in seconds

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTOR);
    
register_clcmd("say /paylas""DonateCmd")
    
register_clcmd("plugin_donate""DonateHandler")
}

public 
client_disconnect(id)
{
    
DonateTarget[id] = -// just for secure
    
LastDonationTime[id] = 0
}

public 
DonateCmd(id)
{
    if( 
get_systime() < (LastDonationTime[id] + DONATION_INTERVAL) )
    {
        
client_print(idprint_chat"You must wait %d minutes between donations"DONATION_INTERVAL 60)
        return 
PLUGIN_HANDLED
    
}

    new 
szItem[64]
    
formatex(szItemcharsmax(szItem), "\y[\w%s\d - \rAKTARMA MENU \y ]"Prefix)

    new 
iMenu menu_create(szItem"donate_handler")

    new 
iPlayers[MAX_PLAYERS], iNum
    get_players
(iPlayersiNum"e", (cs_get_user_team(id) == CS_TEAM_T) ? "TERRORIST" "CT")
    for(new 
iszTempid[10], iPlayer;iNum;i++)
    {
        
iPlayer iPlayers[i]

        if(
iPlayer != id)
        {
            
num_to_str(iPlayerszTempidcharsmax(szTempid))
            
get_user_name(iPlayerszItemcharsmax(szItem))
            
menu_additem(iMenuszItemszTempid)
        }
    }

    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
donate_handler(idiMenuiItem)
{
    if(
iItem == MENU_EXIT)
    {
        
menu_destroy(iMenu)
        
DonateTarget[id] = -1
        
return PLUGIN_HANDLED
    
}
    new 
iData[6], szItemName[MAX_PLAYERS 2], iAccessiCallback
    menu_item_getinfo
(iMenuiItemiAccessiDatacharsmax(iData), szItemNamecharsmax(szItemName), iCallback)

    
DonateTarget[id] = str_to_num(iData)

    if(!
DonateTarget[id])
    {
        
client_print_color(idprint_team_default"%s Bu oyuncu mevcut değil."Prefix)
        
menu_display(idiMenu)
        
DonateTarget[id] = -1
        
return PLUGIN_HANDLED
    
}

    
client_cmd(id"messagemode plugin_donate")

    
client_print_color(idprint_team_default"%s Ne kadar vermek istediğinizi yazin."Prefix)
    return 
PLUGIN_HANDLED
}

public 
DonateHandler(id)
{
    if( 
get_systime() < (LastDonationTime[id] + DONATION_INTERVAL) )
    {
        return 
PLUGIN_HANDLED
    
}
    
    new 
szValue[8]
    
read_argv(1szValuecharsmax(szValue))

    new 
iValue str_to_num(szValue)

    new 
iPlayerXP crxranks_get_user_xp(id)

    if( 
iPlayerXP iValue || iValue <= 0)
    {
        
client_print_color(idprint_team_default"%s Yeterli XP'niz yok."Prefix)
        return 
PLUGIN_CONTINUE
    
}
    
    
crxranks_give_user_xpDonateTarget[id], iValue)
    
crxranks_give_user_xpidiValue * -1)

    new 
szNameGiver[MAX_PLAYERS]
    
get_user_nameidszNameGivercharsmaxszNameGiver))

    new 
szNameReceiver[MAX_PLAYERS]
    
get_user_name(DonateTarget[id], szNameReceivercharsmax(szNameReceiver))

    new 
iPlayers[MAX_PLAYERS], iNum
    get_players
(iPlayersiNum"e", (cs_get_user_team(id) == CS_TEAM_T) ? "TERRORIST" "CT")
    for(new 
i;iNum;i++)
    {
        
client_print_color(iPlayers[i], print_team_default"%s^x04 %s^x01 aktardi^x04 $%i^x01 EXP^x04 %s."PrefixszNameGiveriValueszNameReceiver)
    }
    
client_cmd(DonateTarget[id], "spk ^"items/9mmclip1.wav^"")

    
DonateTarget[id] = -1
    
    LastDonationTime
[id] = get_systime()
    
    return 
PLUGIN_HANDLED

__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-01-2021 , 00:58   Re: Selam
Reply With Quote #7

Setting any default value for DonateTarget[id] doesn't do anything because you are checking it anywhere. The only place that I can think of that should actually check for the default value is in DonationHandler() to make sure that a donation target is set before doing anything since this function is called asynchronously.

In addition to that, in DonationHandler(), the target should be checked to make sure that they are still connected. In fact, even with this check, there is a chance that the target player leaves and a new player connects and gets that same player slot giving the wrong person the donation. This issue can be resolved by storing userid instead if entity id as the donation target. Granted, you would then need to use something like cmd_target() to get the target player in DonationHandler().
__________________
fysiks is offline
Erra
Member
Join Date: Jun 2021
Old 11-01-2021 , 01:54   Re: Selam
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
Setting any default value for DonateTarget[id] doesn't do anything because you are checking it anywhere. The only place that I can think of that should actually check for the default value is in DonationHandler() to make sure that a donation target is set before doing anything since this function is called asynchronously.

In addition to that, in DonationHandler(), the target should be checked to make sure that they are still connected. In fact, even with this check, there is a chance that the target player leaves and a new player connects and gets that same player slot giving the wrong person the donation. This issue can be resolved by storing userid instead if entity id as the donation target. Granted, you would then need to use something like cmd_target() to get the target player in DonationHandler().
I'm so sorry I couldn't add
Erra is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-01-2021 , 22:30   Re: Selam
Reply With Quote #9

Quote:
Originally Posted by Erra View Post
I'm so sorry I couldn't add
Post #7 wasn't directed at you. You only need to add the one line that I mentioned in post #5. However, just in case you're having trouble with that, I've added to my original post. Re-copy the code from post #2.
__________________
fysiks is offline
Erra
Member
Join Date: Jun 2021
Old 11-03-2021 , 00:48   Re: Selam
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
The quickest way is to add

Code:
iValue = (iValue > 10000 ? 10000 : iValue)
immediately after

Code:
new iValue = str_to_num(szValue)
giving:

Code:
	new iValue = str_to_num(szValue)
	iValue = (iValue > 10000 ? 10000 : iValue)
thank you very much sir, but when I type /paylas nothing happens

Last edited by Erra; 11-03-2021 at 01:10.
Erra is offline
Old 11-03-2021, 01:09
Erra
This message has been deleted by Erra.
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:32.


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