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

Solved SwitchToSlot function with new syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 03-03-2020 , 12:59   SwitchToSlot function with new syntax
Reply With Quote #1

How would this stock be updated with the new style declarations?

PHP Code:
stock TF2_SwitchtoSlot(clientslot)
{
    if (
slot >= && slot <= && IsClientInGame(client) && IsPlayerAlive(client))
    {
        new 
String:wepclassname[64];
        new 
wep GetPlayerWeaponSlot(clientslot);
        if (
wep MaxClients && IsValidEdict(wep) && GetEdictClassname(wepwepclassnamesizeof(wepclassname)))
        {
            
FakeClientCommandEx(client"use %s"wepclassname);
            
SetEntPropEnt(clientProp_Send"m_hActiveWeapon"wep);
        }
    }

I read the SourcePan Transitional Syntax wiki, but it isn't written at a level that I can fully understand. Here's where the wiki became too confusing for me:

Quote:
Grammar

The new and old declaration grammar is below.

return-type ::= return-old | return-new
return-new ::= type-expr new-dims? // Note, dims not yet supported.
return-old ::= old-dims? label?

argdecl ::= arg-old | arg-new
arg-new ::= "const"? type-expr '&'? symbol old-dims? ('=' arg-init)?
arg-old ::= "const"? tags? '&'? symbol old-dims? ('=' arg-init)?

Last edited by PC Gamer; 03-03-2020 at 14:30. Reason: Solved
PC Gamer is offline
Maxximou5
AlliedModders Donor
Join Date: Feb 2013
Old 03-03-2020 , 13:09   Re: SwitchToSlot function with new syntax
Reply With Quote #2

I only see three instances of updating. More input is always wanted.

Before:
Spoiler


After:
Spoiler
Maxximou5 is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 03-03-2020 , 14:05   Re: SwitchToSlot function with new syntax
Reply With Quote #3

Quote:
Originally Posted by Maxximou5 View Post
I only see three instances of updating. More input is always wanted.

Before:
Spoiler


After:
Spoiler
You forgot to add void return type.
Code:
stock void TF2_SwitchToSlot(int client, int slot)
// Will be treated by compiler as an error if your function doesn't have return type but you have #pragma newdecls required
__________________

Last edited by MAGNAT2645; 03-03-2020 at 14:09.
MAGNAT2645 is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 03-03-2020 , 14:30   Re: SwitchToSlot function with new syntax
Reply With Quote #4

Thanks Guys! I updated the code with your suggestions and it works great!

Final solution:
PHP Code:
stock void TF2_SwitchtoSlot(int clientint slot)
{
    if (
slot >= && slot <= && IsClientInGame(client) && IsPlayerAlive(client))
    {
        
char wepclassname[64];
        
int wep GetPlayerWeaponSlot(clientslot);
        if (
wep MaxClients && IsValidEdict(wep) && GetEdictClassname(wepwepclassnamesizeof(wepclassname)))
        {
            
FakeClientCommandEx(client"use %s"wepclassname);
            
SetEntPropEnt(clientProp_Send"m_hActiveWeapon"wep);
        }
    }

PC Gamer 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 16:02.


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