Raised This Month: $12 Target: $400
 3% 

Subplugin Submission AmmoPacks per map (like Lgk)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Noam
Member
Join Date: Jun 2019
Old 09-12-2019 , 13:43   AmmoPacks per map (like Lgk)
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <zombieplague>
#include <ColorChat>
new Trie:used_command

public plugin_init()
{
register_plugin("AmmoPacks Per Map""1.1""Hades ~~~`");

register_clcmd("say /rtd""ApCommand");
register_clcmd("say rtd""ApCommand");
register_clcmd("say /free""ApCommand");
register_clcmd("say /get""ApCommand");
used_command TrieCreate()
}
public 
ApCommand(id)
{
new 
szAuthid[35]
get_user_authid(id szAuthid charsmax(szAuthid)) // szAuthid now contains user authid
if( TrieKeyExistsused_commandszAuthid ) )  // if we have szAuthid in trie 
{
ColorChat(id,NORMAL"You already^3 used^1 this command^4 Try^3 NextMap^1.");
}
else
{
new 
Random random_num(1,4)
switch(
Random)
{
case 
0:
{
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + 20);
ColorChat(id,NORMAL"You have got^3 20^1 ammopacks for^3 using^1 a legit client.");
}
case 
1:
{
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + 30);
ColorChat(id,NORMAL"You have got^3 30^1 ammopacks for^3 using^1 a legit client.");
}
case 
2:
{
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + 40);
ColorChat(id,NORMAL"You have got^3 40^1 ammopacks for^3 using^1 a legit client.");
}
case 
3:
{
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + 50);
ColorChat(id,NORMAL"You have got^3 50^1 ammopacks for^3 using^1 a legit client.");
}
}
}
TrieSetCellused_commandszAuthid)  // save user authid in tire
}
public 
plugin_end( )
{
    
TrieDestroyused_command )

rtd,free,get system random ammopacks between 20-50. you can edit.
Thanks to @LearninG for saving each player using command.

Last edited by Noam; 09-13-2019 at 14:27. Reason: Update
Noam is offline
DON KHAN 1
Senior Member
Join Date: Mar 2019
Location: Pakistan
Old 09-13-2019 , 01:21   Re: AmmoPacks per map (like Lgk)
Reply With Quote #2

this plugin looks like get ap plugin but give random ammo packs.
nice plugin
__________________
Facebook
My YouTube
Ro{Y}aL WarLanD CommuniTy
Selling Zombie CSO 4.3 Money System Mod
DON KHAN 1 is offline
AmXDusT
Member
Join Date: Feb 2019
Location: Italy / Albania
Old 09-13-2019 , 04:06   Re: AmmoPacks per map (like Lgk)
Reply With Quote #3

Not sure if that's how it's supposed to be, but consider resetting used_command[id] when id disconnects.
AmXDusT is offline
Noam
Member
Join Date: Jun 2019
Old 09-13-2019 , 04:30   Re: AmmoPacks per map (like Lgk)
Reply With Quote #4

Quote:
Originally Posted by AmXDusT View Post
Not sure if that's how it's supposed to be, but consider resetting used_command[id] when id disconnects.
nope, i have checked that.

only when map restart/change you can use it again.

Last edited by Noam; 09-13-2019 at 04:39.
Noam is offline
AmXDusT
Member
Join Date: Feb 2019
Location: Italy / Albania
Old 09-13-2019 , 04:59   Re: AmmoPacks per map (like Lgk)
Reply With Quote #5

Quote:
Originally Posted by Noam View Post
nope, i have checked that.

only when map restart/change you can use it again.
Let's say you're in-game. You use your command and get the free ammos and then you leave.
Another player joins, he hasn't used that command yet. He writes the command but plugin tells him "you've already used", because his id will be the same as previous player's.

You should reset "used_command" when player disconnects ( or joins the server ) and check whether a player has used command by steamid or name. You should use tries for that.
AmXDusT is offline
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 09-13-2019 , 06:27   Re: AmmoPacks per map (like Lgk)
Reply With Quote #6

If using tries , bool is not necessary , create trie on plugin_init() , on ApCommand get user authid , check if it matches with what we have in trie , after giving ammo packs save user authid in trie so we know this authid has used command ( we will block him to access the command later by checking trie value ) and at last destroy trie on plugin_end() to free up memory.

example code :
Code:
#include <amxmodx> #include <cstrike> new Trie:g_tUsedCommand public plugin_init() {         register_plugin("free money per map" , "1.0" , "LearninG")         register_clcmd("say /money" , "give_money")         g_tUsedCommand = TrieCreate() } public give_money(id) {         new szAuthid[35]         get_user_authid(id , szAuthid , charsmax(szAuthid)) // szAuthid now contains user authid         if( TrieKeyExists( g_tUsedCommand, szAuthid ) )  // if we have szAuthid in trie         {                 client_print(id , print_chat , "[AMXX] You have used this command")         }         else         {                 cs_set_user_money(id , cs_get_user_money(id) + 5000)                 client_print(id , print_chat, "[AMXX] You got 5000 money")                 TrieSetCell( g_tUsedCommand, szAuthid, 1 )  // save user authid in trie         } } public plugin_end( ) {     TrieDestroy( g_tUsedCommand ) }
for more information about Tries : https://forums.alliedmods.net/showthread.php?t=201872

Last edited by LearninG; 09-13-2019 at 15:53.
LearninG is offline
Noam
Member
Join Date: Jun 2019
Old 09-13-2019 , 14:27   Re: AmmoPacks per map (like Lgk)
Reply With Quote #7

Edited the code, Thanks to LearninG
Noam 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 11:20.


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