help loop foreach
#1

Код:
public OnFilterScriptInit()
{
        foreach(new i: Player)
                {
                SetPVarInt(i, "laser", 0);
                SetPVarInt(i, "color", 18643);
        }
        return 1;
}
 
public OnFilterScriptExit()
{
        foreach(new i: Player)
                {
                SetPVarInt(i, "laser", 0);
                RemovePlayerAttachedObject(i, 0);
        }
        return 1;
}
How can I change this to loop? thanks in advance!
Reply
#2

pawn Код:
foreach(new i: Player)
becomes

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
Foreach is faster though since it loops through online players ONLY.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
foreach(new i: Player)
becomes

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
Foreach is faster though.
I would definitely use foreach but the problem was I get this error

I already add #include <foreach>

Код:
 undefined symbol "foreach"
error 029: invalid expression, assumed zero
error 017: undefined symbol "Player"
fatal error 107: too many error messages on one lin
Reply
#4

Is it like that?

pawn Код:
#include <a_samp>
// first include is a_samp always, then the rest..
#include <foreach>

// Somewhere below:
foreach(new i: Player)
By the way, update the include to the latest version because the syntax has been changed.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Is it like that?

pawn Код:
#include <a_samp>
// first include is a_samp always, then the rest..
#include <foreach>

// Somewhere below:
foreach(new i: Player)
By the way, update the include to the latest version because the syntax has been changed.
Please what is this " warning 203: symbol is never used: "params"

from

Код:
dcmd_laser(playerid,params[])
{
	SetPVarInt(playerid, "laser", 1);
	SetPVarInt(playerid, "color", GetPVarInt(playerid, "color"));
	return 1;
}

dcmd_laseroff(playerid,params[])
{
	SetPVarInt(playerid, "laser", 0);
	RemovePlayerAttachedObject(playerid, 0);
	return 1;
}
Reply
#6

pawn Код:
dcmd_laser(playerid,params[])
{
    #pragma unused params
    SetPVarInt(playerid, "laser", 1);
    SetPVarInt(playerid, "color", GetPVarInt(playerid, "color"));
    return 1;
}

dcmd_laseroff(playerid,params[])
{
    #pragma unused params
    SetPVarInt(playerid, "laser", 0);
    RemovePlayerAttachedObject(playerid, 0);
    return 1;
}
EDIT: lol iZN.

1 nanosecond = 1.0 Ч 10(^-9) seconds and the difference between our posts was 1 minute!
Reply
#7

You're using dcmd, practically old command processor. Use
pawn Код:
#pragma unused params
EDIT: err, late some nanoseconds.
Reply
#8

You shouldn't be using dcmd, consider switching to zcmd, also easier to use.
https://sampforum.blast.hk/showthread.php?tid=91354
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
dcmd_laser(playerid,params[])
{
    #pragma unused params
    SetPVarInt(playerid, "laser", 1);
    SetPVarInt(playerid, "color", GetPVarInt(playerid, "color"));
    return 1;
}

dcmd_laseroff(playerid,params[])
{
    #pragma unused params
    SetPVarInt(playerid, "laser", 0);
    RemovePlayerAttachedObject(playerid, 0);
    return 1;
}
EDIT: lol iZN.

1 nanosecond = 1.0 Ч 10(^-9) seconds and the difference between our posts was 1 minute!
Quote:
Originally Posted by iZN
Посмотреть сообщение
You're using dcmd, practically old command processor. Use
pawn Код:
#pragma unused params
EDIT: err, late some nanoseconds.
Quote:
Originally Posted by Mean
Посмотреть сообщение
You shouldn't be using dcmd, consider switching to zcmd, also easier to use.
https://sampforum.blast.hk/showthread.php?tid=91354
Lol iZN. Thanks guys its all working. Thank you in advice. If you mind Im using this processor because I been using this for almost 2 years without any problem ingame. Lastly I have this problem arranging.

I want it to be exactly like this below.

Код:
Player Statistics 

TheDream (ID:98)

General:
- Total Time Logged in: 
- Ping:

Scores:
- Kills: 
- Ratio:
- Money: 

Game: 
- Virtual World: 
- Interior:
- Wanted Level: 
- Skin: 
- PM's:
- Go's:
- God:
Here is the code..

Код:
dcmd_stats(playerid,params[])
{
    new str[512], pDeaths, player1, h, m, s;
    new status[2][10] = {"Disabled", "Enabled"};
    if(!strlen(params)) player1 = playerid;
    else player1 = strval(params);
    if(!IsPlayerConnected(player1)) return SendClientMessage(playerid, white, "{FF0000}>> Player not Connected");
    TotalGameTime(player1, h, m, s);
    if(AccInfo[player1][Deaths] == 0) pDeaths = 1;
    else pDeaths = AccInfo[player1][Deaths];
    format(str, sizeof(str), "{DAA520}%s (ID: %d){B0C4DE}\n\n", PlayerName2(player1), player1);
    format(str, sizeof(str), "%sSkinID: %d\n", str, GetPlayerSkin(player1));
    format(str, sizeof(str), "%sScore: %d\n", str, GetPlayerScore(player1));
    format(str, sizeof(str), "%sKills: %d\n", str, AccInfo[player1][Kills]);
    format(str, sizeof(str), "%sMoney: $%d\n", str, GetPlayerMoney(player1));
    format(str, sizeof(str), "%sRatio: %.2f\n", str, Float:AccInfo[player1][Kills]/Float:pDeaths);
    format(str, sizeof(str), "%sInterior: %d\n", str, GetPlayerInterior(player1));
    format(str, sizeof(str), "%sVirtual World: %d\n", str, GetPlayerVirtualWorld(player1));
    format(str, sizeof(str), "%sWanted Level: %d\n\n", str, GetPlayerWantedLevel(player1));
    format(str, sizeof(str), "%sPM: %s\n", str, status[GetPVarInt(player1, "PMEnabled")]);
    format(str, sizeof(str), "%sGod: %s\n", str, status[GetPVarInt(player1, "GodMode")]);
    format(str, sizeof(str), "%sGo's: %s\n\n", str, status[GetPVarInt(player1, "GotoEnabled")]);
    format(str, sizeof(str), "%sPing: %d\n", str, GetPlayerPing(player1));
    format(str, sizeof(str), "%sTime Login: %d hours %d minutes %d seconds\n", str, h, m, s);
    ShowPlayerDialog(playerid, 8435, DIALOG_STYLE_MSGBOX, "Player Statistics", str, "Close", "");
    return 1;
}
#endif
Reply
#10

Use strcat to join both two strings.
pawn Код:
dcmd_stats(playerid,params[])
{
    new pDeaths, player1, h, m, s, str[512], str1[128];
    new status[2][10] = {"Disabled", "Enabled"};
    if(!strlen(params)) player1 = playerid;
    else player1 = strval(params);
    if(!IsPlayerConnected(player1)) return SendClientMessage(playerid, white, "{FF0000}>> Player not Connected");
    TotalGameTime(player1, h, m, s);
    if(AccInfo[player1][Deaths] == 0) pDeaths = 1;
    else pDeaths = AccInfo[player1][Deaths];
    format(str, sizeof(str), "{DAA520}%s (ID: %d){B0C4DE}\n\n", PlayerName2(player1), player1);
    str1 = "General:\n";
    strcat(str,str1);
    format(str, sizeof(str), "%sTime Login: %d hours %d minutes %d seconds\n", str, h, m, s);
    format(str, sizeof(str), "%sPing: %d\n", str, GetPlayerPing(player1));
    str1 = "Scores:\n";
    strcat(str,str1);
    format(str, sizeof(str), "%sScore: %d\n", str, GetPlayerScore(player1));
    format(str, sizeof(str), "%sKills: %d\n", str, AccInfo[player1][Kills]);
    format(str, sizeof(str), "%sMoney: $%d\n", str, GetPlayerMoney(player1));
    format(str, sizeof(str), "%sRatio: %.2f\n", str, Float:AccInfo[player1][Kills]/Float:pDeaths);
    str1 = "Game:\n";
    strcat(str,str1);
    format(str, sizeof(str), "%sSkinID: %d\n", str, GetPlayerSkin(player1));
    format(str, sizeof(str), "%sInterior: %d\n", str, GetPlayerInterior(player1));
    format(str, sizeof(str), "%sVirtual World: %d\n", str, GetPlayerVirtualWorld(player1));
    format(str, sizeof(str), "%sWanted Level: %d\n\n", str, GetPlayerWantedLevel(player1));
    format(str, sizeof(str), "%sPM: %s\n", str, status[GetPVarInt(player1, "PMEnabled")]);
    format(str, sizeof(str), "%sGod: %s\n", str, status[GetPVarInt(player1, "GodMode")]);
    format(str, sizeof(str), "%sGo's: %s\n\n", str, status[GetPVarInt(player1, "GotoEnabled")]);
    strcat(str,str1);
    ShowPlayerDialog(playerid, 8435, DIALOG_STYLE_MSGBOX, "Player Statistics", str, "Close", "");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)