Scripting Problem, explanation requested.
#1

I'm trynna learn scripting, and I tried making a LSPD system, which is on proccess, I failed on making /duty work, and /lspdadminset so if you're admin, to set your team in LSPD.
Fix the code for me, and tell me what I did wrong, I know i've done many mistakes, I'm a beginer.
PHP код:
#include <a_samp>
#include <a_http>
#include <MidoStream>
#include <zcmd>
#include <GeoIP_Plugin>
#include <gtazones>
#include <streamer>
#define Group
#define team_lspd   1 // team to design lspd officers
#define team_civ    2// civ team
#define COLOR_YELLOW      0xFFFF00AA
public OnPlayerCommandText(playeridcmdtext[])
{
     if(!
strcmp(cmdtext"/duty"))
     
GetPlayerPos(playeridxyz);
     }
     if(
pTeam[playerid] == team_civ){ // Check if the player is a civilian
     
SendClientMessage(playeridCOLOR_YELLOW"You are not a LSPD officer");
        if new 
string1[] = (IsPlayerPosplayerid 0,1575.8651,-1690.4974,6.2188,359.9606,0,0,0,0,0,0)
        
SetPlayerSkin(playeid300)
        
SendClientMessage(playerid0xFFFFFFFF"You've gone on duty");
        if(!
strcmp(string1falseSendClientMessage "You must be at duty point!"))
        
        return 
1;
     }
     return 
0;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
     if(!
strcmp(cmdtext"/lspdadminset"))
     {
        if(!
IsPlayerConnected(i) || IsPlayerAdmin(i))continue;
        
SendClientMessage(playerid0xFFFFFFFF"You're LSPD now!");
        
pTeam[playerid] = team_lspd;
        return 
1;
     }
     return 
0;

REMINDER: I'm a newbie on scripting.
Reply
#2

A) You can't have two of a same callback, you can simply merge the code together so:

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
     if(!
strcmp(cmdtext"/lspdadminset"))
     {
     
//Your stuff here
     
}
     else if(!
strcmp(cmdtext"/duty"))
     {
     
//Your stuff here
     
}
     return 
0;

B) I really wish you would learn how to use ZCMD and sscanf instead of strcmp and strtok (Believe me it's way easier than learning to work with this method you are doing, the tutorial you are following is really outdated, look for +2013 ones so you would learn the power of ZCMD(or YCMD) and sscanf together.)
Reply
#3

Thanks for the advice, I'll improve my scripting and learn these two plugins.
Reply
#4

Beside the fact that you can't use the same callback twice, you have made several other mistakes.

First of all, I would recommend taking a looking here https://sampwiki.blast.hk/wiki/Category...es_.28pVars.29 to get familiar with SA-MP's functions & natives.


Now lets get on with your code.

Код:
if new string1[] = (IsPlayerPos, playerid 0,1575.8651,-1690.4974,6.2188,359.9606,0,0,0,0,0,0);
What's the point of defining string as a variable here then typing that right after it ? a string is a sequence of characters, either as a literal constant or as some kind of variable - So there's no point of assigning a string to those type of numbers.


When you take a look at the wiki, you'll notice that there's a function called IsPlayerInRangeOfPoint - I'll tell you how to use it later on,

Код:
if(!strcmp(string1, false, SendClientMessage "You must be at duty point!"))
Not how it works either.

In PAWN [and most coding languages] - we use if & elseif. Its quite logical, The code detects "IF" a certain condition is happening, if its not - then "else if" something else will happen.

So here's how your code should look like.

Код:
if(!strcmp(cmdtext, "/duty")) 
{
   if(!IsPlayerInRangeOfPoint(playerid 0,1575.8651,-1690.4974,6.2188,359.9606,0,0,0,0,0,0)) return     SendClientMessage(playerid, -1,  You're not at the duty location!");
   {
     if(!(pTeam[playerid] == team_cops)) return SendClientMessage(playerid, -1, "You cant use this!");
     {
        SetPlayerSkin(playeid, 300) 
        SendClientMessage(playerid, 0xFFFFFFFF, "You've gone on duty"); 
        return 1;
     }
  }
}
I've written this code on my phone so I am not so sure if everything is correct but that's how it should generally look, plus I haven't checked any of the parameters of your IsPlayerInRangeOfPoint.

Same thing for this code tho.

Код:
     if(!strcmp(cmdtext, "/lspdadminset")) 
     { 
        if(!IsPlayerConnected(i) || IsPlayerAdmin(i))continue; 
        SendClientMessage(playerid, 0xFFFFFFFF, "You're LSPD now!"); 
        pTeam[playerid] = team_lspd; 
        return 1; 
     }
if(!IsPlayerConnected(i) <- You dont need to use i as its not defined, playerid is defined by default to retrieve the ID of the player who typed the command so you'd use if(!IsPlayerConnected(playerid))

No point of using continue; either - you'd just use brackets to keep going.

So your code should look something like this:

Код:
     if(!strcmp(cmdtext, "/lspdadminset")) 
     { 
        if(!IsPlayerConnected(playerid) || IsPlayerAdmin(playerid))
        {
        SendClientMessage(playerid, 0xFFFFFFFF, "You're LSPD now!"); 
        pTeam[playerid] = team_lspd; 
        return 1; 
        }
     }
Keep in mind that "||" will search if either of the statements are true NOT both and if one of them is, it will keep going, so in your situation, I would recommend using "&&" as it checks if both statements are true.

I would also HIGHLY recommend using sscanf & ZCMD, beside the fact that they are so much faster, its ALOT easier to understand and use them than strcmp and strtok especially that you're still learning.


Quote:
Originally Posted by DRP
Посмотреть сообщение
Thanks for the advice, I'll improve my scripting and learn these two plugins.
There's a difference between a callback, function & a plugin.

These are the plugins: http://forum.sa-mp.com/forumdisplay.php?f=18

If you're really serious about wanting to learn how to script - I would start with reading this documentary http://www.compuphase.com/pawn/Pawn_Language_Guide.pdf - it covers everything about PAWN and its REALLY helpful.
Reply
#5

Thanks, I'll read all of those when I'm back home from school .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)