Raised This Month: $ Target: $400
 0% 

String not printing properly.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
P1raten
Senior Member
Join Date: Feb 2010
Old 02-06-2013 , 17:25   String not printing properly.
Reply With Quote #1

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
__________________
No salvation. Only madness.
P1raten is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-06-2013 , 17:34   Re: String not printing properly.
Reply With Quote #2

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).
__________________
Arkshine is offline
P1raten
Senior Member
Join Date: Feb 2010
Old 02-06-2013 , 17:35   Re: String not printing properly.
Reply With Quote #3

Quote:
Originally Posted by Arkshine View Post
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.
__________________
No salvation. Only madness.

Last edited by P1raten; 02-06-2013 at 17:35.
P1raten is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 02-06-2013 , 17:46   Re: String not printing properly.
Reply With Quote #4

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
Doc-Holiday is offline
P1raten
Senior Member
Join Date: Feb 2010
Old 02-06-2013 , 18:32   Re: String not printing properly.
Reply With Quote #5

Any advantages? Besides reducing the amount of lines written.

Might profile it later and check if there's any considerable difference in speed.
__________________
No salvation. Only madness.
P1raten is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 02-06-2013 , 18:35   Re: String not printing properly.
Reply With Quote #6

Quote:
Originally Posted by P1raten View Post
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
Doc-Holiday is offline
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 20:36.


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