AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Not Working (https://forums.alliedmods.net/showthread.php?t=184234)

shavit 05-02-2012 14:41

Not Working
 
Im trying to do something with my "Bunnyhop Commands" Plugin.
Code:

new tele_saved[MAXPLAYERS+1];
new Float:checkpoint[MAXPLAYERS+1][3];

        RegConsoleCmd("sm_save", Command_save, "Saving a Checkpoint on The Client Position.");
        RegConsoleCmd("sm_tele", Command_tele, "Teleport to your Saved Checkpoint.");
        RegConsoleCmd("sm_s", Command_save, "Saving a Checkpoint on The Client Position.");
        RegConsoleCmd("sm_t", Command_tele, "Teleport to your Saved Checkpoint.");

public Action:Command_save(client, args)
{
        GetEntPropVector(client, Prop_Send, "m_vecOrigin", checkpoint[client]);
        tele_saved[client] = 1;
        PrintToChat(client, "\x04[SM]\x01 CheckPoint Saved.");
}

public Action:Command_tele(client, args)
{
        if(checkpoint = true)
        {
                TeleportEntity(client, checkpoint[client], NULL_VECTOR, NULL_VECTOR);
                PrintToChat(client, "\x04[SM]\x01 Teleported to Checkpoint.");
        }
        else
        {
                PrintToChat(client, "\x04[SM]\x01 You Have to Place a Checkpoint First, Type !s/!save for that.)");
        }
}

Error:
PHP Code:

/groups/sourcemod/upload_tmp/textHwQcDO.sp(253) : warning 211possibly unintended assignment
/groups/sourcemod/upload_tmp/textHwQcDO.sp(253) : error 047: array sizes do not match, or destination array is too small 


Lord Canistra 05-02-2012 14:49

Re: Not Working
 
Are you sure you posted the part of code which produces errors? Because I what's wrong about this piece.
Also, using PHP tag in first case and CODE in second would be more appropriate.

extrospect 05-02-2012 15:24

Re: Not Working
 
You're doing an assignment operation (A = B) instead of a comparison operation (A == B) in this if statement:

Code:

if(checkpoint = true)
{
        TeleportEntity(client, checkpoint[client], NULL_VECTOR, NULL_VECTOR);
        PrintToChat(client, "\x04[SM]\x01 Teleported to Checkpoint.");
}
else
{
        PrintToChat(client, "\x04[SM]\x01 You Have to Place a Checkpoint First, Type !s/!save for that.)");
}

You are also failing to index the checkpoint array, but I believe, from the code you posted, you actually want to be checking the tele_saved array not the checkpoint array - the fixed code would be:

Code:

if(tele_saved[client] == 1)
{
        TeleportEntity(client, checkpoint[client], NULL_VECTOR, NULL_VECTOR);
        PrintToChat(client, "\x04[SM]\x01 Teleported to Checkpoint.");
}
else
{
        PrintToChat(client, "\x04[SM]\x01 You Have to Place a Checkpoint First, Type !s/!save for that.)");
}

Also, it would probably be a good idea to tag the tele_saved array as 'bool:' and populate it with falses by default:
Code:

new bool:tele_saved[MAXPLAYERS+1] = { false, ... };
Then you can change this line for type clarity:
Code:

tele_saved[client] = true;
The last two points don't really affect how the code will function but are merely good practice for maintaining clarity on what the various arrays are storing (in this case a boolean).

The complete example would then be:
Code:

new bool:tele_saved[MAXPLAYERS+1] = { false, ... };
new Float:checkpoint[MAXPLAYERS+1][3];

        RegConsoleCmd("sm_save", Command_save, "Saving a Checkpoint on The Client Position.");
        RegConsoleCmd("sm_tele", Command_tele, "Teleport to your Saved Checkpoint.");
        RegConsoleCmd("sm_s", Command_save, "Saving a Checkpoint on The Client Position.");
        RegConsoleCmd("sm_t", Command_tele, "Teleport to your Saved Checkpoint.");

public Action:Command_save(client, args)
{
        GetEntPropVector(client, Prop_Send, "m_vecOrigin", checkpoint[client]);
        tele_saved[client] = true;
        PrintToChat(client, "\x04[SM]\x01 CheckPoint Saved.");
}

public Action:Command_tele(client, args)
{
        if(tele_saved[client])
        {
                TeleportEntity(client, checkpoint[client], NULL_VECTOR, NULL_VECTOR);
                PrintToChat(client, "\x04[SM]\x01 Teleported to Checkpoint.");
        }
        else
        {
                PrintToChat(client, "\x04[SM]\x01 You Have to Place a Checkpoint First, Type !s/!save for that.)");
        }
}


TheAvengers2 05-02-2012 15:42

Re: Not Working
 
Any particular reason for using GetEntPropVector "m_vecOrigin" over GetClientAbsOrigin? :?

shavit 05-03-2012 04:57

Re: Not Working
 
The guy that helped me, take a crabs or w/e is it! [i cant place it because somebody disabled my BBCode]

Quote:

Originally Posted by TheAvengers2 (Post 1700657)
Any particular reason for using GetEntPropVector "m_vecOrigin" over GetClientAbsOrigin? :?

What is the different?

Also, im trying to get the menu api to work to update my bhop commands plugin, ive readed the Menu API in the Sourcemod "wiki" and i still got nothing.

Somebody can give me an example of a menu that im setting the title and 6 options and every option will do "return Plugin_Handled;"?


All times are GMT -4. The time now is 04:59.

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