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

String To Vector?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pear
Member
Join Date: May 2017
Location: sea
Old 07-12-2017 , 08:44   String To Vector?
Reply With Quote #1

How do I convert a string containing 3 numbers into a vector?

So I need this

PHP Code:
mystring[64] = "30 0 -28" 
converted into this

PHP Code:
vec[0] = 30.0
vec
[1] = 0.0
vec
[2] = -28.0 
EDIT:

Nevermind i figured it out after posting it >~<

This is how I did it:

PHP Code:
    char mystring[64] = "30 0 -28"num1[32], num2[32], num3[32];
    
int index;  
    
float vector[3];
    
index BreakString(mystringnum1sizeof(num1));
    
strcopy(mystringsizeof(mystring), mystring[index]);
    
index BreakString(mystringnum2sizeof(num2));
    
strcopy(mystringsizeof(mystring), mystring[index]);
    
BreakString(mystringnum3sizeof(num3));
    
vector[0] = StringToFloat(num1);
    
vector[1] = StringToFloat(num2);
    
vector[2] = StringToFloat(num3);
    
PrintToServer("%.0f %.0f %.0f"vector[0], vector[1], vector[2]); 
EDIT 2:

PHP Code:
    char mystring[64] = "30 0 -282";
    
char num[64][3];
    
float vector[3]; 
    
ExplodeString(mystring" "num3sizeof(num), false);
    
vector[0] = StringToFloat(num[0]);
    
vector[1] = StringToFloat(num[1]);
    
vector[2] = StringToFloat(num[2]);
    
PrintToServer("%.0f %.0f %.0f"vector[0], vector[1], vector[2]); 
explode string made it look fancier
ty to hmmmmm guy

Last edited by pear; 07-12-2017 at 10:41.
pear is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 07-12-2017 , 09:13   Re: String To Vector?
Reply With Quote #2

Could also ExplodeString by spaces
hmmmmm is offline
pear
Member
Join Date: May 2017
Location: sea
Old 07-12-2017 , 10:22   Re: String To Vector?
Reply With Quote #3

oh! that makes it look cleaner thanks
pear is offline
Reply


Thread Tools
Display Modes

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 01:48.


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