AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   String not printing properly. (https://forums.alliedmods.net/showthread.php?t=207780)

P1raten 02-06-2013 17:25

String not printing properly.
 
On client_authorized i use the copy function to assign a weapon to a global variable with id as key.

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <engine>
#include <fun>
#include <hamsandwich>

new g_iWep[33];
new 
g_iAmmo[33];

new const 
Weapon[][] =
{
    
"weapon_glock18",
    
"weapon_usp",
    
"weapon_p228",
    
"weapon_deagle",
    
"weapon_fiveseven",
    
"weapon_elite"
};

new const 
Ammo[][] =
{
    
"ammo_9mm",
    
"ammo_45acp",
    
"ammo_357sig",
    
"ammo_50ae",
    
"ammo_57mm"
};

public 
plugin_init()
{
    
register_plugin(PluginVersionAuthor);

    
RegisterHam(Ham_Spawn"player""fwHamPlayerSpawnPost"1);
}
{...}
public 
client_authorized(id)
{
    
copy(g_iWep[id], charsmax(g_iWep), Weapon[0]);
    
copy(g_iAmmo[id], charsmax(g_iAmmo), Ammo[0]);
}
{...}
public 
fwHamPlayerSpawnPost(iPlayer)
{
    if (
is_user_alive(iPlayer))
    {
        
give_item(iPlayerg_iWep[iPlayer]);
        
give_item(iPlayerg_iAmmo[iPlayer]);
    }
}
{...} 

If i print this in the same function then it displays properly as "weapon_glock18". Which is what I desire.

However, when trying to give the weapon to a player it does not always work.

I printed out in the server the player id and the weapon.

PHP Code:

Player ID(Wepwweapon_glock18)
Player ID(Wepweapon_glock18)
Player ID(Wepwweapon_glock18)
Player ID(Wepweapon_glock18)
Player ID(Wepweapon_glock18)
Player ID(Wepweapon_glock18)
Player ID(Wepeapon_glock18)
Player ID(Wepweapon_glock18)
Player ID(Wepeapon_glock18


Arkshine 02-06-2013 17:34

Re: String not printing properly.
 
new g_iWep[33][ 20 ];
new g_iAmmo[33][ 20 ];

You forget the buffer since you store strings. And 20 because the max length of a weapon name is 19 (weapon_smokegrenade).

P1raten 02-06-2013 17:35

Re: String not printing properly.
 
Quote:

Originally Posted by Arkshine (Post 1888699)
new g_iWep[33][ 20 ];
new g_iAmmo[33][ 20 ];

You forget the buffer since you store strings. And 20 because the max length of a weapon name is 19 (weapon_smokegrenade).

Thank you, it was driving me crazy.

EDIT: I guess I was too tired to realize it.

Doc-Holiday 02-06-2013 17:46

Re: String not printing properly.
 
Noticed you were giving ammo via actually giving the item. You can set bp ammo using a native from cstrike.

PHP Code:

new g_WeaponBPAmmo[] =
{
    
052090132110090112010010090909010012030,    12020032901209023590900100
};

cs_set_user_bpammo(idiWeapong_WeaponBPAmmo[iWeapon]) 

iWeapon is the CSW weapon constraint. like CSW_M4A1

P1raten 02-06-2013 18:32

Re: String not printing properly.
 
Any advantages? Besides reducing the amount of lines written.

Might profile it later and check if there's any considerable difference in speed.

Doc-Holiday 02-06-2013 18:35

Re: String not printing properly.
 
Quote:

Originally Posted by P1raten (Post 1888742)
Any advantages? Besides reducing the amount of lines written.

Might profile it later and check if there's any considerable difference in speed.

just the ease of it

give_item()
give_item()
give_item()
give_item()

vs one line


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

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