AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   About A Plugin That Compiled Successfully but Doesn't Work (https://forums.alliedmods.net/showthread.php?t=312888)

Jess98 12-19-2018 06:45

About A Plugin That Compiled Successfully but Doesn't Work
 
Hi, I have made a simple plugin which gives ammo packs to players who use the valid nicknames that I wrote when they connect server. As I said in the title, it compiled without any errors. I also tried it with the forward "client_putinserver()" but still same. What's wrong with this?

Code:

#include <amxmodx>
#include <zombieplague>

#define PLUGIN "Giving Ammo Packs When Valid Nicknames Perception"
#define VERSION "1.0"
#define AUTHOR "Jess"

public plugin_init() {

      register_plugin(PLUGIN, VERSION, AUTHOR)

      register_clcmd("say /sil", "Event_Of_Remove_Ammo_Packs")
      register_clcmd("say /sil", "Event_Of_Remove_Ammo_Packs")
}

public client_connect(ID) {

      new Get_Player_Name[32]
      get_user_name(ID, Get_Player_Name, charsmax(Get_Player_Name))

      if(equali(Get_Player_Name, "Alex"))
      {
              client_print_color(ID, ID, "^4Hey, welcome to the server. You have got ^399999 Ammo Packs. ^4Enjoy the game!")
              client_print_color(ID, ID, "^4Hey, welcome to the server. You have got ^399999 Ammo Packs. ^4Enjoy the game!")
              client_print_color(ID, ID, "^4Hey, welcome to the server. You have got ^399999 Ammo Packs. ^4Enjoy the game!")

              zp_set_user_ammo_packs(ID, zp_get_user_ammo_packs(ID) + 99999)
      }
         
      else if(equali(Get_Player_Name, "Kevin"))
      {
              client_print_color(ID, ID, "^4Hey, welcome to the server. You have got ^399999 Ammo Packs. ^4Enjoy the game!")
              client_print_color(ID, ID, "^4Hey, welcome to the server. You have got ^399999 Ammo Packs. ^4Enjoy the game!")
              client_print_color(ID, ID, "^4Hey, welcome to the server. You have got ^399999 Ammo Packs. ^4Enjoy the game!")

              zp_set_user_ammo_packs(ID, zp_get_user_ammo_packs(ID) + 99999)
      }
}

public Event_Of_Remove_Ammo_Packs(ID) {

      zp_set_user_ammo_packs(ID, zp_get_user_ammo_packs(ID) - 97000)
}


OciXCrom 12-19-2018 06:53

Re: A Plugin That Compiles Successful but Doesn't Work
 
There is nothing strange in a compiled plugin that doesn't work. If everything is written as it should for the computer to read, it doesn't mean the in-game logic is correct as well.

client_connect is called when the player is still connecting, so he can't possibly see the chat message. Try using client_putinserver and/or a 1-2 seconds task to delay the function.

Jess98 12-19-2018 08:45

Re: About A Plugin That Compiled Successfully but Doesn't Work
 
Quote:

Originally Posted by OciXCrom (Post 2629922)
There is nothing strange in a compiled plugin that doesn't work. If everything is written as it should for the computer to read, it doesn't mean the in-game logic is correct as well.

client_connect is called when the player is still connecting, so he can't possibly see the chat message. Try using client_putinserver and/or a 1-2 seconds task to delay the function.

I knew it already, I didn't mean that if a plugin compiled without any error then it works as successful in the game while writing the title of this subject. And, I tried "client_putinserver()" before but it didn't work as I said on the top.

Shortly before, changed the if queries as

if(is_user_connected(ID) && equali(Get_Player_Name, "Alex"))
else if(is_user_connected(ID) && equali(Get_Player_Name, "Kevin"))

with using the forward "client_connect()" but still same. I'll try to use set_task when I have time to look at this problem.

OciXCrom 12-19-2018 14:12

Re: About A Plugin That Compiled Successfully but Doesn't Work
 
There's no point in checking if the user is connected in those forwards. If they were called, the user is 100% connected.

fysiks 12-19-2018 20:42

Re: About A Plugin That Compiled Successfully but Doesn't Work
 
How do you expect to give ammo to a player that isn't 1) on a team and 2) alive? Is there something strange about ZombiePlague that makes it actually work that way?

OciXCrom 12-20-2018 08:41

Re: About A Plugin That Compiled Successfully but Doesn't Work
 
Quote:

Originally Posted by fysiks (Post 2630058)
How do you expect to give ammo to a player that isn't 1) on a team and 2) alive? Is there something strange about ZombiePlague that makes it actually work that way?

It's not ammo, it's ammo packs. They work like credits/money, so there's no reason for the player to be alive or in a team.

iceeedr 12-20-2018 09:58

Re: About A Plugin That Compiled Successfully but Doesn't Work
 
The problem can be in the check of the name, for example create a const with the steamids, and check the putin server if get_user_authid is equal to const [i], it is not difficult and it is a better method ...

CrazY. 12-20-2018 17:54

Re: About A Plugin That Compiled Successfully but Doesn't Work
 
The best way probably would be in client_authorized instead of client_connect or client_putinserver.

LondoN 12-21-2018 12:25

Re: About A Plugin That Compiled Successfully but Doesn't Work
 
Code:

#include < amxmodx >

native zp_set_user_ammo_packs ( Player, Packs );
native zp_get_user_ammo_packs ( Player );

new const szNames [ ] [ ] =
{
        "Alex",
        "Kevin"
};

new g_PlayerName [ 33 ] [ 32 ];

const Size = sizeof szNames;

public plugin_init ( )        register_clcmd ( "say /sil", "RemovePacks" );
public RemovePacks ( id )
{
        for ( new i = 0; i < Size; i++ )
        {
                if ( equal ( g_PlayerName [ id ], szNames [ i ] ) )
                        zp_set_user_ammo_packs ( id, zp_get_user_ammo_packs ( id ) - 97000 );
        }
}

public client_putinserver ( id )
{
        if ( is_user_bot ( id ) || is_user_hltv ( id ) )
                return;

        get_user_name ( id, g_PlayerName [ id ], charsmax ( g_PlayerName ) );

        set_task ( 1.0, "GivePlayerPacks", id );
}

public GivePlayerPacks ( id )
{
        for ( new i = 0; i < Size; i++ )
        {
                if ( equal ( g_PlayerName [ id ], szNames [ i ] ) )
                {
                        zp_set_user_ammo_packs ( id, 99999 );
                        client_print ( id, print_chat, "[ZP] Hey, welcome to the server. You have got 99999 Ammo Packs" );
                }
        }
}

If you want to give packs to multiple names, my oppinion is .. the loop is the best way..and the client_putinserver is the perfect forward to execute. Otherwise at /sil you need to check names again .. else all players can remove packs and will be -1, -2 ammo packs per id.


All times are GMT -4. The time now is 07:36.

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