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

Return an array in stock


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 10-18-2017 , 04:45   Return an array in stock
Reply With Quote #1

Hey. First of all, thank you for explaining in details why should I use cstrike/fun/engine modules instead of converting them. I really did get the point and appreceate that you dealt with my narrow-mindness till the end

I wanted to ask some help regarding stocks. I want to create a stock that would do the following:

Code:
stock get_team_colours( id, rgb[ 3 ] ) {         if( cs_get_user_team( id ) == CS_TEAM_T ) {              rgb[ 0 ] = 255;              rgb[ 1 ] = 0;              rgb[ 2 ] = 75;         }         else //... return rgb; }

But this does not work. Could you please tell me how can I achieve the wanted result?
__________________
I ONLY LOVE STEAM, NON-STEAM IS VERY BAD FOR YOUR HEALTH!
Kowalsky is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-18-2017 , 06:14   Re: Return an array in stock
Reply With Quote #2

The stock already does what you want it to do (trust me, try it). Remove the return rgb; line and you're good to go.
__________________

Last edited by OciXCrom; 10-18-2017 at 06:14.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-18-2017 , 09:10   Re: Return an array in stock
Reply With Quote #3

The important thing to understand here is that arrays are passed by reference aka 'byref' in this language.

That means that when you manipulate an array variable inside your function, it actually changes the variable in the calling code which was provided as the argument.
__________________
fysiks is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 10-18-2017 , 09:14   Re: Return an array in stock
Reply With Quote #4

In amxx it is not possible to return an array or a string (basically in amxx string is an array of integers that actually can also be understood as chars).

So in this case you have just to use the function with an empty array as input. And then function will just save the rgb values directly in that array.

This will your stock look like:

PHP Code:
stock get_team_coloursidrgb] ) {
        if( 
cs_get_user_teamid ) == CS_TEAM_T ) {
             
rgb] = 255;
             
rgb] = 0;
             
rgb] = 75;
        }

And this way you call the function:

PHP Code:
new myRGB[3]

get_team_coloursidmyRGB 
After calling the function, myRGB array will have your desired values.
siriusmd99 is offline
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 10-18-2017 , 10:13   Re: Return an array in stock
Reply With Quote #5

Understood! Thank you
__________________
I ONLY LOVE STEAM, NON-STEAM IS VERY BAD FOR YOUR HEALTH!
Kowalsky is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-18-2017 , 12:36   Re: Return an array in stock
Reply With Quote #6

Quote:
In amxx it is not possible to return an array or a string
You can return a string.
__________________

Last edited by OciXCrom; 10-18-2017 at 12:36.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-18-2017 , 12:46   Re: Return an array in stock
Reply With Quote #7

But returning a string is bad best is to copy it byref
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 10-18-2017 , 13:04   Re: Return an array in stock
Reply With Quote #8

Quote:
Originally Posted by Natsheh View Post
But returning a string is bad best is to copy it byref
That's true, it's more efficient and flexible (doesn't have to be constant size). However, it's good that OcixCrom posted because we shouldn't spread false information.
klippy is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 10-18-2017 , 14:35   Re: Return an array in stock
Reply With Quote #9

Yeah, I know it's possible to return string, but still I can't understand why is not a good idea?! Can anyone explain please? :p

Last edited by KiLLeR.; 10-18-2017 at 14:36.
KiLLeR. is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-18-2017 , 15:04   Re: Return an array in stock
Reply With Quote #10

Quote:
Originally Posted by KiLLeR. View Post
Yeah, I know it's possible to return string, but still I can't understand why is not a good idea?! Can anyone explain please? :p
I'm pretty sure someone(Klippy? PRoSToTeM@?) posted a good explanations about that. You should try searching.
__________________
HamletEagle 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 18:54.


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