SA-MP Forums Archive
for on array - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: for on array (/showthread.php?tid=550614)



for on array - Onepind - 13.12.2014

Why do us need to make for loop?
its enum + array..
like:
PHP код:
enum TELE_DATA
{
    
TELE_CMD[16],
    
Float:TELE_POS_X,
    
Float:TELE_POS_Y,
    
Float:TELE_POS_Z,
    
TELE_MESSAGE[32],
    
TELE_WEAPON,
    
TELE_AMMO,
    
TELE_MONEY,
    
TELE_INTERIOR,
    
TELE_VIRTUAL_WORLD

PHP код:
new pTele[][TELE_DATA] =
{
    {
"/Ramp"1859.3246, -1381.732413.5625"!бшелйн дбайн мжйшъ дшофд"00000}
}; 
PHP код:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    for(new 
isizeof(pTele); ji++)
    {
        if(
strcmp(cmdtextpTele[i][TELE_CMD], true))
        {
            if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                
SetVehiclePos(GetPlayerVehicleID(playerid), pTele[i][TELE_POS_X], pTele[i][TELE_POS_Y], pTele[i][TELE_POS_Z]);
            }
            else 
SetPlayerPos(playeridpTele[i][TELE_POS_X], pTele[i][TELE_POS_Y], pTele[i][TELE_POS_Z]);
            
GivePlayerWeapon(playeridpTele[i][TELE_WEAPON], pTele[i][TELE_AMMO]);
            
GivePlayerMoney(playeridpTele[i][TELE_MONEY]);
            
SetPlayerInterior(playeridpTele[i][TELE_INTERIOR]);
            
SetPlayerVirtualWorld(playeridpTele[i][TELE_VIRTUAL_WORLD]);
            
SendClientMessage(playerid, -1pTele[i][TELE_MESSAGE]);
        }
    }
    return 
1;

why we need that for loop?
When we need do it?

thanx..


Re: for on array - Mic_H - 14.12.2014

The for loop is made to make the script check all Tele_CMD of pTele till the right one is found. If it wasnt for the for loop inside OnPlayerCommandPerformed, you would have to:
PHP код:
CMD:dm1(...)
{
    
setpos
}
CMD:dm2(...)
{
    
setpos
}
.
.
etc

Its, infact, tiresome to script so many commands.. Now this makes your work easy as hell. To add a TP command, you can just add: {"cmdname".......VirtualWorld} to the bottom of the Array...

When do you make Enum+Array? Array can only hold one type of variable when it stands alone.. But with Enum, it becomes flexible.. It can store: Float, Integer, String, Bool, Timer, Text, PlayerText, etc with the help of ENUM.
In your case, the Enum makes space inside the Array from 0-15 for string, 16 for Tele_pos_x, etc.. Again, I am just saying it from what I KNOW, and I dont think am good enough to teach others.. Refer: https://sampforum.blast.hk/showthread.php?tid=318307


Re: for on array - Onepind - 14.12.2014

Quote:
Originally Posted by Mic_H
Посмотреть сообщение
The for loop is made to make the script check all Tele_CMD of pTele till the right one is found. If it wasnt for the for loop inside OnPlayerCommandPerformed, you would have to:
PHP код:
CMD:dm1(...)
{
    
setpos
}
CMD:dm2(...)
{
    
setpos
}
.
.
etc

Its, infact, tiresome to script so many commands.. Now this makes your work easy as hell. To add a TP command, you can just add: {"cmdname".......VirtualWorld} to the bottom of the Array...

When do you make Enum+Array? Array can only hold one type of variable when it stands alone.. But with Enum, it becomes flexible.. It can store: Float, Integer, String, Bool, Timer, Text, PlayerText, etc with the help of ENUM.
In your case, the Enum makes space inside the Array from 0-15 for string, 16 for Tele_pos_x, etc.. Again, I am just saying it from what I KNOW, and I dont think am good enough to teach others.. Refer: https://sampforum.blast.hk/showthread.php?tid=318307
Thank you (:


Re: for on array - Onepind - 15.12.2014

Quote:
Originally Posted by ******
Посмотреть сообщение
Questions like this are about the underlying PAWN language, and are (mostly) all covered in this document:

pawn-lang.pdf

Please read that before asking any more questions.
WTF! ****** commented on my Thread
Thank you, i will read it.