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

[ZPS]Cutting String


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xerox8521
Senior Member
Join Date: Sep 2011
Old 09-22-2011 , 08:42   [ZPS]Cutting String
Reply With Quote #1

Hi,

im new to sourcemod scripting and having problems with cutting a string.. tried it with Explodestring, Split string and nothing happend..

i want to cut of the "weapon_" part of weapon names. so instead of weapon_m4 it just says m4
xerox8521 is offline
Zylius
SourceMod Donor
Join Date: Nov 2009
Old 09-22-2011 , 08:47   Re: [ZPS]Cutting String
Reply With Quote #2

Quote:
Originally Posted by xerox8521 View Post
Hi,

im new to sourcemod scripting and having problems with cutting a string.. tried it with Explodestring, Split string and nothing happend..

i want to cut of the "weapon_" part of weapon names. so instead of weapon_m4 it just says m4
You can do this in many ways. Few examples
ReplaceString(STRING, sizeof(STRING), "weapon_", "", false);
Or just use STRING[7] (using the index specify the character, from which you want to use STRING)

Last edited by Zylius; 09-23-2011 at 05:29.
Zylius is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 09-22-2011 , 08:49   Re: [ZPS]Cutting String
Reply With Quote #3

ok ill try this out now and Edit if it worked or not

edit: hmm didnt worked still displaying the weapon_ part

Last edited by xerox8521; 09-22-2011 at 09:07. Reason: didnt worked
xerox8521 is offline
Zylius
SourceMod Donor
Join Date: Nov 2009
Old 09-22-2011 , 11:46   Re: [ZPS]Cutting String
Reply With Quote #4

Quote:
Originally Posted by xerox8521 View Post
ok ill try this out now and Edit if it worked or not

edit: hmm didnt worked still displaying the weapon_ part
I would need a code sample to check what's the problem
Zylius is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 09-23-2011 , 06:06   Re: [ZPS]Cutting String
Reply With Quote #5

PHP Code:
    new client GetClientOfUserId(GetEventInt(event"userid"));
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
decl String:Name[64];
    
decl String:Name2[64];
    
decl String:weapon_name[64];
    new 
health GetClientHealth(attacker);
    
GetClientName(attackerNamesizeof(Name));
    
GetClientName(clientName2sizeof(Name2));
    
GetClientWeapon(attackerweapon_namesizeof(weapon_name));
    
ReplaceString(weapon_namesizeof(weapon_name), "weapon_"""false);
    
PrintToChat(client,"\x04[SM] %s has killed you with a %s and has %d hp left",Name,weapon_name,health);
    
PrintToChat(attacker"\x04[SM] You have killed %s with a %s",Name2,weapon_name); 
xerox8521 is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 09-23-2011 , 07:58   Re: [ZPS]Cutting String
Reply With Quote #6

Try replacing
PHP Code:
ReplaceString(weapon_namesizeof(weapon_name), "weapon_"""false);
PrintToChat(client,"\x04[SM] %s has killed you with a %s and has %d hp left",Name,weapon_name,health);
PrintToChat(attacker"\x04[SM] You have killed %s with a %s",Name2,weapon_name); 
with
PHP Code:
PrintToChat(client,"\x04[SM] %s has killed you with a %s and has %d hp left",Name,weapon_name[7],health);
PrintToChat(attacker"\x04[SM] You have killed %s with a %s",Name2,weapon_name[7]); 

__________________
hleV is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 09-23-2011 , 11:19   Re: [ZPS]Cutting String
Reply With Quote #7

Now it works thanks for your help
xerox8521 is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 09-23-2011 , 11:49   Re: [ZPS]Cutting String
Reply With Quote #8

Also, instead of manually reading the client names, use the proper formatting tools.
You aren't using it anywhere out of format-compliant functions, so simply doing
Code:
PrintToChat(whoever, "name: %N", Client);
will print the name of that client nr.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys 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 11:38.


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