AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Syntax help (https://forums.alliedmods.net/showthread.php?t=327077)

arijan 08-31-2020 10:09

Syntax help
 
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 :fox:

arijan 08-31-2020 10:31

Re: Syntax help
 
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?

Black Rose 08-31-2020 12:03

Re: Syntax help
 
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.


All times are GMT -4. The time now is 13:56.

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