AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   New syntax troubles (https://forums.alliedmods.net/showthread.php?t=296782)

wwahgnerbp 04-28-2017 16:42

New syntax troubles
 
Hello I'm trying to transfer this to the new syntax:

Code:

stock ZMarketCookiesToArray(client, String:rebuyweapons[WeaponsSlot][], maxweapons, maxlen)
becoming:

Code:

stock void ZMarketCookiesToArray(int client, String:rebuyweapons[WeaponsSlot][], int maxweapons, int maxlen)
the problem is that I have no idea how to convert the String: tagging thing. The transitional API says that we need to specify the size if the brackets come after the variable then I try this:

Code:

stock void ZMarketCookiesToArray(int client, char rebuyweapons[WeaponsSlot][], int maxweapons, int maxlen)
where WeaponsSlot is an enum:

Code:

/**
 * Weapon slots.
 */
enum WeaponsSlot
{
        Slot_Invalid                = -1,  /** Invalid weapon (slot). */
        Slot_Primary                = 0,        /** Primary weapon slot. */
        Slot_Secondary          = 1,        /** Secondary weapon slot. */
        Slot_Melee                  = 2,        /** Melee (knife) weapon slot. */
        Slot_Projectile        = 3,        /** Projectile (grenades, flashbangs, etc) weapon slot. */
        Slot_Explosive          = 4,        /** Explosive (c4) weapon slot. */
        Slot_NVGs                  = 5,        /** NVGs (fake) equipment slot. */
}

but the compiler gives me this:

error 159: brackets after variable name indicate a fixed-size array, but size could not be determined - either specify sizes, an array initializer, or use dynamic syntax (such as 'char[] x')

Is there a possibility to solve that?

Also I have another doubt.

Usually when we want to declare multiple variables with the same value we do:

int a, b, c, d; (all initialized as 0)

in the old syntax we could do this:

Code:

new targets[MAXPLAYERS], bool:tn_is_ml, result;
how can I do the same thing in the new syntax?

If I try to make it like:

Code:

int targets[MAXPLAYERS], bool tn_is_ml, result;
it won't work and the compiler suggest to use the operator view_as :shock:

I use that here:

Code:

result = ProcessTargetString(target, client, targets, sizeof(targets), COMMAND_FILTER_ALIVE, targetname, sizeof(targetname), tn_is_ml);
Any help will be appreciated.

Chaosxk 04-28-2017 17:16

Re: New syntax troubles
 
You don't have to define a size (WeaponsSlot), you can do this:

PHP Code:

stock void ZMarketCookiesToArray(int clientchar[][] rebuyweaponsint maxweaponsint maxlen

and for your 2nd question you can do this:

PHP Code:

int targets[MAXPLAYERS]; bool tn_is_mlint result;
result ProcessTargetString(targetclienttargetssizeof(targets), COMMAND_FILTER_ALIVEtargetnamesizeof(targetname), tn_is_ml); 

or

PHP Code:

int targets[MAXPLAYERS], tn_is_mlresult;
result ProcessTargetString(targetclienttargetssizeof(targets), COMMAND_FILTER_ALIVEtargetnamesizeof(targetname), view_as<bool>(tn_is_ml)); 


wwahgnerbp 04-28-2017 17:40

Re: New syntax troubles
 
I forgot to mention that rebuyweapons is declared like this:
Code:

char rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH];
Here's the full code

Code:

/**
 * Force a client to rebuy their weapons.
 *
 * @param client        The client index.
 */
void ZMarketRebuy(int client, bool autorebuy = false)
{
        // If client is dead, then stop.
        if (!IsPlayerAlive(client))
        {
                TranslationPrintToChat(client, "Must be alive");
                return;
        }
       
        // If client is a zombie, then stop.
        if (InfectIsClientInfected(client))
        {
                TranslationPrintToChat(client, "Must be human");
                return;
        }
       
        bool zmarketbuyzone = GetConVarBool(g_hCvarsList[CVAR_WEAPONS_ZMARKET_BUYZONE]);
        if (!autorebuy && zmarketbuyzone && !WeaponsIsClientInBuyZone(client))
        {
                TranslationPrintToChat(client, "Weapons zmarket buyzone");
                return;
        }
       
        // Transfer cookie values into an array.
        char rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH];
        ZMarketCookiesToArray(client, rebuyweapons, WEAPONS_SLOTS_MAX + 1, sizeof(rebuyweapons[]));
       
       
        // x = Weapon slot.
        for (int x = 0; x < WEAPONS_SLOTS_MAX + 1; x++)
        {
                // If slot is empty, then stop.
                if (!rebuyweapons[x][0])
                {
                        continue;
                }
               
                ZMarketEquip(client, rebuyweapons[x], true);
        }
}

Code:

stock void ZMarketCookiesToArray(int client, char[][] rebuyweapons, int maxweapons, int maxlen)
{
        char rebuycookiename[32];
        Handle rebuycookie;
       
        // x = Weapon slot.
        for (int x = 0; x < maxweapons; x++)
        {
                // Format cookie name.
                Format(rebuycookiename, sizeof(rebuycookiename), "%s_%d", ZMARKET_COOKIE_REBUY, x);
               
                // Find cookie handle, and retrieve its value.
                rebuycookie = FindClientCookie(rebuycookiename);
                GetClientCookie(client, rebuycookie, rebuyweapons[x], maxlen);
                CloseHandle(rebuycookie);
        }
}

When I try as you suggested the compiler gives me two errors but it manages to generate the binary

// zr/weapons/zmarket.inc(1168) : warning 213: tag mismatch
// zr/weapons/zmarket.inc(1168) : warning 229: index tag mismatch (symbol "rebuyweapons")


What does these errors means? How can I solve that?

WildCard65 04-28-2017 18:30

Re: New syntax troubles
 
PHP Code:

char rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH

in param definition, but anything passed to that param must match array size (or greater?)

Chaosxk 04-28-2017 18:37

Re: New syntax troubles
 
Dynamic array so gotta convert it to this:

PHP Code:

char[][] rebuyweapons = new char[WeaponsSlot][WEAPONS_MAX_LENGTH];
ZMarketCookiesToArray(1rebuyweaponsWEAPONS_SLOTS_MAX 1WEAPONS_MAX_LENGTH); 


wwahgnerbp 04-28-2017 20:16

Re: New syntax troubles
 
that makes sense now. And I have a last question I promise :D

let's say we have this

Code:

KnockbackSetVelocity(client, const Float:startpoint[3], const Float:endpoint[3], Float:magnitude)
if I convert the float variables to this

Code:

void KnockbackSetVelocity(int client, const float startpoint[3], const float endpoint[3], float magnitude)
can it be also expressed like this?:

Code:

void KnockbackSetVelocity(int client, const float[3] startpoint, const float[3] endpoint, float magnitude)
Is float[3] endpoint and float endpoint[3] the same thing?

I ended up having this doubt too after reading BAILOPAN's first post from 2014 where he demonstrates us how weird would it be if we try to express this using the tagging system and the declaration rules of chars also contributed to increase my doubts

his example:
Code:

native float[3] GetEntOrigin();

Chaosxk 04-28-2017 23:05

Re: New syntax troubles
 
Yes, they seem to work the same way.

wwahgnerbp 04-29-2017 00:32

Re: New syntax troubles
 
Quote:

Originally Posted by Chaosxk (Post 2516743)
Yes, they seem to work the same way.

Alright thank you very much! :bacon!:

asherkin 04-29-2017 04:49

Re: New syntax troubles
 
No, they're different - but the difference is immaterial until SourcePawn moves further along.

float[3] foo = type is float[3], a fixed array of 3 floats, foo is a single float[3].
float bar[3] = type is float, bar is a dynamic array of 3 floats.

You almost always want the former, especially for vectors.

wwahgnerbp 04-29-2017 10:22

Re: New syntax troubles
 
Quote:

Originally Posted by asherkin (Post 2516775)
No, they're different - but the difference is immaterial until SourcePawn moves further along.

float[3] foo = type is float[3], a fixed array of 3 floats, foo is a single float[3].
float bar[3] = type is float, bar is a dynamic array of 3 floats.

You almost always want the former, especially for vectors.

Alright Mr. Asher I can see now. Thank you for clarifying this.


All times are GMT -4. The time now is 18:46.

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