AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Zombie Plague Mod (https://forums.alliedmods.net/forumdisplay.php?f=126)
-   -   Subplugin Submission AmmoPacks per map (like Lgk) (https://forums.alliedmods.net/showthread.php?t=318653)

Noam 09-12-2019 13:43

AmmoPacks per map (like Lgk)
 
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.

DON KHAN 1 09-13-2019 01:21

Re: AmmoPacks per map (like Lgk)
 
this plugin looks like get ap plugin but give random ammo packs.
nice plugin

AmXDusT 09-13-2019 04:06

Re: AmmoPacks per map (like Lgk)
 
Not sure if that's how it's supposed to be, but consider resetting used_command[id] when id disconnects.

Noam 09-13-2019 04:30

Re: AmmoPacks per map (like Lgk)
 
Quote:

Originally Posted by AmXDusT (Post 2666804)
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.

AmXDusT 09-13-2019 04:59

Re: AmmoPacks per map (like Lgk)
 
Quote:

Originally Posted by Noam (Post 2666806)
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.

LearninG 09-13-2019 06:27

Re: AmmoPacks per map (like Lgk)
 
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

Noam 09-13-2019 14:27

Re: AmmoPacks per map (like Lgk)
 
Edited the code, Thanks to LearninG


All times are GMT -4. The time now is 23:54.

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