Include help please
#1

Hey guys. I want to work with includes because I have to make a lot of commands.
Now I want to have all my commands in an include

I'm emberrased to say that I've never done this before :P
I'm not a very decent scripter.
I want to give more time in scripting now so can someone tell me how to start working with includes?

Like how to get a commands like this in an include?:

pawn Код:
COMMAND:kick(playerid,params[])
{
new reason[50],id,string[286];
if(adminlevel[playerid] <1) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
if(sscanf(params,"us[50]",id,reason)) return SendClientMessage(playerid, COLOR_GREY, "HINT: /kick [playerid] [reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
format(string,sizeof(string),"Admin %s has kicked %s Reason: %s",playername,playername2,reason);
SendClientMessageToAll(COLOR_RED,string);
Kick(id);
return 1;
}
Reply
#2

If you put the command inside an include and include it in your code the command will work.
Example
pawn Код:
#if defined _bartje_included
  #endinput
#endif


COMMAND:kick(playerid,params[])
{
new reason[50],id,string[286];
if(adminlevel[playerid] <1) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
if(sscanf(params,"us[50]",id,reason)) return SendClientMessage(playerid, COLOR_GREY, "HINT: /kick [playerid] [reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
format(string,sizeof(string),"Admin %s has kicked %s Reason: %s",playername,playername2,reason);
SendClientMessageToAll(COLOR_RED,string);
Kick(id);
return 1;
}
And use this (if the name of the include is bartje)
pawn Код:
#include <bartje>
Reply
#3

Why the f*** is your string 286 cells big (Sorry offtopic)
Reply
#4

My include looks like this now:

pawn Код:
COMMAND:kick(playerid,params[])
{
new reason[50],id;
if(adminlevel[playerid] <1) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
if(sscanf(params,"us[50]",id,reason)) return SendClientMessage(playerid, COLOR_GREY, "HINT: /kick [playerid] [reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
format(string,sizeof(string),"Admin %s has kicked %s Reason: %s",playername,playername2,reason);
SendClientMessageToAll(COLOR_RED,string);
Kick(id);
return 1;
}

COMMAND:help(playerid,params[])
{
ShowPlayerDialog(playerid,7,DIALOG_STYLE_LIST,"Help","Commands\nRules","Ok","Cancel");
return 1;
}

COMMAND:stats(playerid,params[])
{

SendClientMessage(playerid,COLOR_YELLOW,"_________________________________________________");
GetPlayerName(playerid, playername, sizeof(playername));
format(string,sizeof(string),"%s's stats:",playername);
SendClientMessage(playerid,COLOR_YELLOW,string);
format(string,sizeof(string),"||Money: %d||Age: %d||",money[playerid],age[playerid]);
SendClientMessage(playerid,COLOR_YELLOW,string);
if(adminlevel[playerid] >=1)
{
format(string,sizeof(string),"||Adminlevel: %d||",adminlevel[playerid]);
SendClientMessage(playerid,COLOR_YELLOW,string);
}
SendClientMessage(playerid,COLOR_YELLOW,"_________________________________________________");
return 1;
}

COMMAND:eat(playerid,params[])
{

    new choice[20];
    if(sscanf(params,"s",choice)) return SendClientMessage(playerid, COLOR_GREY, "HINT: /eat [fish]");
    else
    {
        if(!strcmp(choice,"fish",true))
        {
        if(fishes[playerid]<1) return SendClientMessage(playerid, COLOR_RED, "You need atleast one fish");
        else
        GivePlayerHealth(playerid,20);
        new Float:eathealth;
        GetPlayerHealth(playerid,eathealth);
        if (eathealth >= 80.0)
        {
        SetPlayerHealth(playerid, 100.0);
        }
        fishes[playerid] -=1;
        SendClientMessage(playerid,COLOR_YELLOW,"You've eaten a fish. 20 Health added.");
        return 1;
        }
        else
        SendClientMessage(playerid,COLOR_RED,"Invalid choice");

    }
    return 1;
}

COMMAND:fishstats(playerid,params[])
{
new string2[100];
format(string,sizeof(string),"Fishes: %d",fishes[playerid]);
SendClientMessage(playerid,COLOR_DARKORANGE,string);
format(string2,sizeof(string2),"Fish EXP: %d/100",fishexp[playerid]);
SendClientMessage(playerid,COLOR_DARKORANGE,string2);
return 1;
}

COMMAND:laseron(playerid,params[])
{
SetPVarInt(playerid, "laser", 1);
SetPVarInt(playerid, "color", GetPVarInt(playerid, "color"));
return 1;
}

COMMAND:laseroff(playerid,params[])
{
SetPVarInt(playerid, "laser", 0);
RemovePlayerAttachedObject(playerid, 0);
return 1;
}

COMMAND:lasercol(playerid,params[])
{
new color[40];
if(!strcmp(color,"blue",true))
{
SetPVarInt(playerid, "color", 19080);
}
else
{
SendClientMessage(playerid,COLOR_RED,"Invalid choice");
}
return 1;
}
////////////////////////////////////////////////////////////////////////////////

//admin commands////////////////////////////////////////////////////////////////

//level1
COMMAND:kick(playerid,params[])
{
new reason[50],id;
if(adminlevel[playerid] <1) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
if(sscanf(params,"us[50]",id,reason)) return SendClientMessage(playerid, COLOR_GREY, "HINT: /kick [playerid] [reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
format(string,sizeof(string),"Admin %s has kicked %s Reason: %s",playername,playername2,reason);
SendClientMessageToAll(COLOR_RED,string);
Kick(id);
return 1;
}
COMMAND:mute(playerid,params[])
{
new id,time;
if(adminlevel[playerid] <1) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
if(sscanf(params,"ui",id,time)) return SendClientMessage(playerid, COLOR_GREY, "HINT: /mute [playerid] [time]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
SetTimerEx("mutetimer",time*1000, false, "i", id);
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
format(string,sizeof(string),"%s has been muted by admin %s for %d seconds",playername2,playername2,time);
SendClientMessageToAll(COLOR_RED,string);
muted[id] = 1;
return 1;
}
//level2
COMMAND:sfl(playerid,params[])
{
new gang[50],id;
if(adminlevel[playerid] <3) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
if(sscanf(params,"us[50]",id,gang)) return SendClientMessage(playerid, COLOR_GREY, "HINT: /sfl [playerid] [Faction Name]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
{
if(!strcmp(gang,"lspd",true))
{

cop[id] = 10;
InFaction[id] = 10;
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
format(string,sizeof(string),"You've been made leader of Los Santos Police Department by %s",playername);
SendClientMessage(id,COLOR_YELLOW,string);
format(string,sizeof(string),"You've made %s leader of Los Santos Police Department",playername2);
SendClientMessage(playerid,COLOR_YELLOW,string);
}
else
if(!strcmp(gang,"grove",true))
{
grove[id] = 10;
InFaction[id] = 10;
format(string,sizeof(string),"You've been made leader of Grove Street Families by %s",playername);
SendClientMessage(id,COLOR_YELLOW,string);
format(string,sizeof(string),"You've made %s leader of Grove Street Families",playername2);
SendClientMessage(playerid,COLOR_YELLOW,string);
}
else
{
SendClientMessage(playerid,COLOR_RED,"Invalid choice");
SendClientMessage(playerid,COLOR_GREY,"Valid Choices: lspd,grove");
}
}
return 1;
}

COMMAND:ban(playerid,params[])
{
new reason[50],id;
if(adminlevel[playerid] <2) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
if(sscanf(params,"us[50]",id,reason)) return SendClientMessage(playerid, COLOR_GREY, "HINT: /ban [playerid] [reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
format(string,sizeof(string),"Admin %s has banned %s Reason: %s",playername,playername2,reason);
SendClientMessageToAll(COLOR_RED,string);
Ban(id);
return 1;
}
//level3
COMMAND:setstat(playerid,params[])
{
    new stat[20],id,value;
    if(adminlevel[playerid] <2) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
    if(sscanf(params,"us[20]d",id,stat,value)) return SendClientMessage(playerid, COLOR_GREY, "HINT: /setstat [playerid] [stat] [amount]"); // We use return here to make sure that if the parameters aren't set, the code doesn't continue!
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
    else // This will work in this case without wrapping the following code without brackets because it's followed by an if statement which will continue the chain, BUT it's much neater and more readable to wrap the following in brackets
    {
        GetPlayerName(playerid, playername, sizeof(playername));
        GetPlayerName(id, playername2, sizeof(playername2));
        if(!strcmp(stat,"money",true))
        {
            money[id] = value;
            SetPlayerMoney(id,value);
            format(string,sizeof(string),"Your money has been setted to %d by Admin %s",value,playername);
            SendClientMessage(id,COLOR_YELLOW,string);
            format(string,sizeof(string),"You've setted %s's money to %d",playername2,value);
            SendClientMessage(playerid,COLOR_YELLOW,string);
        }
        else if(!strcmp(stat,"age",true))
        {
            age[id] = value;
            SetPlayerScore(id,value);
            format(string,sizeof(string),"Your age has been setted to %d by Admin %s",value,playername);
            SendClientMessage(id,COLOR_YELLOW,string);
            format(string,sizeof(string),"You've setted %s's age to %d",playername2,value);
            SendClientMessage(playerid,COLOR_YELLOW,string);
        }
        else if(!strcmp(stat,"fishes",true))
        {
            fishes[id] = value;
            format(string,sizeof(string),"Your fishes has been setted to %d by Admin %s",value,playername);
            SendClientMessage(id,COLOR_YELLOW,string);
            format(string,sizeof(string),"You've setted %s's fishes to %d",playername2,value);
            SendClientMessage(playerid,COLOR_YELLOW,string);
        }
        else // You need to wrap the following code in brackets here, as you have multiple functions you want to run should the else statement be true.
        {
            SendClientMessage(playerid,COLOR_RED,"Invalid choice");
            SendClientMessage(playerid,COLOR_GREY,"Valid Choices: money,age,fishes");
        }
    }
    return 1;
}

COMMAND:giveweapon(playerid,params[])
{
new id,gun,ammo;
if(adminlevel[playerid]<3) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
if(sscanf(params,"udd",id,gun,ammo)) return SendClientMessage(playerid,COLOR_GREY,"HINT: /giveweapon [playerid] [weaponid] [ammo]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
GivePlayerWeapon(id,gun,ammo);
return 1;
}

//level4
COMMAND:night(playerid,params[])
{
if(adminlevel[playerid] <4) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
else
SetWorldTime(0);
return 1;
}
//rcon//
COMMAND:makeadmin(playerid,params[])
{

new level,id;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
if(sscanf(params,"ud",id,level)) return SendClientMessage(playerid,COLOR_GREY,"HINT: /makeadmin [playerid] [level]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
format(string,sizeof(string),"Admin %s has made %s admin level %d",playername,playername2,level);
SendClientMessageToAll(COLOR_YELLOW,string);
adminlevel[id] = level;
return 1;
}


////////////////////////////////////////////////////////////////////////////////

//job commands//////////////////////////////////////////////////////////////////
COMMAND:fish(playerid,params[])
{
if(inmission[playerid] == 1) return SendClientMessage(playerid,COLOR_RED,"Another mission is started already");
if(!IsPlayerInRangeOfPoint(playerid, 7.0, 2941.1365,-2051.7290,3.5480)) return SendClientMessage(playerid,COLOR_RED,"You're not at the fishing place");
if(fishprogress[playerid] > 0) return SendClientMessage(playerid,COLOR_RED,"You're already doing this job!");
else
fishprogress[playerid] = 1;
SendClientMessage(playerid,COLOR_YELLOW,"You've started your fishing job. Take a boat and go to the checkpoints!");
SetPlayerCheckpoint(playerid,3019.4819,-1259.1970,0.8884,4.0);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
//faction commands//////////////////////////////////////////////////////////////
COMMAND:recruit(playerid,params[])
{
new id;
if(InFaction[playerid] <8) return SendClientMessage(playerid,COLOR_RED,"You need atleast rank 8 to recruit someone into a faction");
if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_GREY,"HINT: /recruit [playerid]");
if(InFaction[id] >=1) return SendClientMessage(playerid,COLOR_RED,"This player is already in another faction");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
{
if(cop[playerid] >=8)
{
ShowPlayerDialog(id,copdialog,DIALOG_STYLE_MSGBOX,"Faction Invite","You've been invited for Los Santos Police Department","Accept","Cancel");
}
else
if(grove[playerid] >=8)
{
ShowPlayerDialog(id,grovedialog,DIALOG_STYLE_MSGBOX,"Faction Invite","You've been invited for Grove Street Families","Accept","Cancel");
}
}
return 1;
}

COMMAND:leavefaction(playerid,params[])
{
if(InFaction[playerid] <1) return SendClientMessage(playerid,COLOR_RED,"You're not even in any faction");
else
InFaction[playerid] = 0;

return 1;
}

COMMAND:wanted(playerid,params[])
{
new id,wanted,reason[100];
if(cop[playerid] <1) return SendClientMessage(playerid,COLOR_RED,"You're not a cop!");
if(sscanf(params,"uds[100]",id,wanted,reason)) if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_GREY,"HINT: /wanted [playerid] [level] [reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else
{
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
SetPlayerWantedLevel(id,wanted);
format(string,sizeof(string),"%s has made you a level %d suspect. Reason:%s",playername,wanted,reason);
SendClientMessage(id,COLOR_YELLOW,string);
format(string,sizeof(string),"You've made %s wanted level %d. Reason:%s",playername2,wanted,reason);
SendClientMessage(playerid,COLOR_YELLOW,string);
}
return 1;
}

COMMAND:arrest(playerid,params[])
{
new id;

if(cop[playerid] <1) return SendClientMessage(playerid,COLOR_RED,"You're not a cop!");
if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_GREY,"HINT: /arrest [playerid]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
if(GetPlayerWantedLevel(id) <1) return SendClientMessage(playerid,COLOR_RED,"This is not a wanted player!");
if(!IsPlayerInRangeOfPlayer(playerid,id,2)) return SendClientMessage(playerid,COLOR_RED,"You're not in range of this player");
if(cuffed[id] <1) return SendClientMessage(playerid,COLOR_RED,"This player isn't cuffed /cuff him");
if(jailed[id] >=1) return SendClientMessage(playerid,COLOR_RED,"This player is in jail");
else
SetTimerEx("outjail", GetPlayerWantedLevel(id)*60000, false, "i", id);
SetPlayerPos(id,266,78,1002);
SetPlayerInterior(id,6);
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
format(string,sizeof(string),"%s is arrested by %s for %d minutes",playername2,playername,GetPlayerWantedLevel(id));
SendClientMessageToAll(COLOR_BLUE,string);
jailed[id] = 1;
TogglePlayerControllable(id,1);
cuffed[id] = 0;
return 1;
}

COMMAND:cuff(playerid,params[])
{
new id;
if(cop[playerid] <1) return SendClientMessage(playerid,COLOR_RED,"You're not a cop!");
if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_GREY,"HINT: /cuff [playerid]");
if(GetPlayerWantedLevel(id) <1) return SendClientMessage(playerid,COLOR_RED,"This is not a wanted player!");
if(!IsPlayerInRangeOfPlayer(playerid,id,2)) return SendClientMessage(playerid,COLOR_RED,"You're not in range of this player");
if(jailed[id] >=1) return SendClientMessage(playerid,COLOR_RED,"This player is in jail");
if(cuffed[id] >=1) return SendClientMessage(playerid,COLOR_RED,"This player is already cuffed");
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, playername2, sizeof(playername2));
format(string,sizeof(string),"%s is cuffed by %s",playername2,playername);
SendClientMessageToAll(COLOR_BLUE,string);
cuffed[id] = 1;
TogglePlayerControllable(id,0);
return 1;
}
Errors:
Код:
C:\Users\Michael\Desktop\Samp scvripting\pawno\include\commands.inc(1) : error 010: invalid function or declaration
C:\Users\Michael\Desktop\Samp scvripting\pawno\include\commands.inc(6) : error 017: undefined symbol "adminlevel"
C:\Users\Michael\Desktop\Samp scvripting\pawno\include\commands.inc(6) : error 017: undefined symbol "COLOR_RED"
C:\Users\Michael\Desktop\Samp scvripting\pawno\include\commands.inc(7) : error 017: undefined symbol "COLOR_GREY"
C:\Users\Michael\Desktop\Samp scvripting\pawno\include\commands.inc(8) : error 017: undefined symbol "COLOR_RED"
C:\Users\Michael\Desktop\Samp scvripting\pawno\include\commands.inc(10) : error 017: undefined symbol "playername"
C:\Users\Michael\Desktop\Samp scvripting\pawno\include\commands.inc(10) : error 017: undefined symbol "playername"
C:\Users\Michael\Desktop\Samp scvripting\pawno\include\commands.inc(10) : error 029: invalid expression, assumed zero
C:\Users\Michael\Desktop\Samp scvripting\pawno\include\commands.inc(10) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


9 Errors.
Even when I define the color in the include it still gives the color errors.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)