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

Syntax help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
arijan
Junior Member
Join Date: Aug 2020
Old 08-31-2020 , 10:09   Syntax help
Reply With Quote #1

Code:
public cmd_glow(id, level, cid)
{
	if (!cmd_access(id, level, cid, 6))
		return PLUGIN_HANDLED

	new szName[32], rgbColor[3][3]
	read_argv(1, szName, charsmax(szName))

	read_argv(2, rgbColor[0], 3)
	read_argv(3, rgbColor[1], 3)
	read_argv(4, rgbColor[2], 3)

	new idGlower = cmd_target(id, szName, CMDTARGET_ALLOW_SELF)

	glow_player(
	idGlower, 
	{ str_to_num(rgbColor[0]), str_to_num(rgbColor[1]), str_to_num(rgbColor[2]) },
	50
	)

	return PLUGIN_HANDLED
}
I'm not sure how to send an array over to my function other than making each RGB value a separate int, here's my glow_player function:

Code:
stock glow_player(id, rgb[3], glowAmount = 40)
{
	set_user_rendering(id, kRenderFxGlowShell, rgb[0], rgb[1], rgb[2], kRenderNormal, glowAmount)
	console_print(0, "Set glowing to id %i with glow amount %i", id, glowAmount)
}
I'm sure there's something simple I'm missing, and thanks for the help in advance
arijan is offline
arijan
Junior Member
Join Date: Aug 2020
Old 08-31-2020 , 10:31   Re: Syntax help
Reply With Quote #2

Apparently my problem is that I can't have variables in an array, is there a workaround or should I set all the arguments to separate ints?
arijan is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-31-2020 , 12:03   Re: Syntax help
Reply With Quote #3

When it comes to server side, you can do basically anything so there's definitely a solution.

I'm not completely sure here but I'm making some guesses.
I think {} is for the compiler, not runtime. So you might not be able to use it dynamically like you are doing. There might be a workaround but I would just reformat it:
Code:
    new rgbiColor[3];     rgbiColor[0] = str_to_num(rgbColor[0]);     rgbiColor[1] = str_to_num(rgbColor[1]);     rgbiColor[2] = str_to_num(rgbColor[2]);     glow_player(idGlower, rgbiColor, 50)
There's no point of storing the string separately, you could just read one, transform it and the read the next.
Throw in some looping just for neatness.
Code:
    new szName[32], rgbColor[3]     for ( new i = 0 ; i < 3 ; i++ ) {         read_argv(i + 2, szName, charsmax(szName)); // Use the szName as a temporary storage since we already have it.         rgbColor[i] = str_to_num(szName);     }     read_argv(1, szName, charsmax(szName)) // After we're done using szName for other purposes, we can use it for what we intended it for.     new idGlower = cmd_target(id, szName, CMDTARGET_ALLOW_SELF)         if ( idGlower ) // Check that cmd_target() actually found a target         glow_player(idGlower, rgbColor, 50)




Also, since the read_argv() function is getting a string you need to leave space for the null at the end. So either limit it to 2 characters using:
Code:
    read_argv(, rgbColor[0], charsmax(rgbColor[])) // which is 2
or increase the size of the string to 3 + null (4):
Code:
    new szName[32], rgbColor[3][4] // ...     read_argv(, rgbColor[0], charsmax(rgbColor[])) // This should be used either way.
But this is already fixed in my previous example.
__________________

Last edited by Black Rose; 08-31-2020 at 12:32.
Black Rose 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:32.


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