SA-MP Forums Archive
Scripting Help - 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: Scripting Help (/showthread.php?tid=625288)



Scripting Help - RyderX - 30.12.2016

Hello dear, i were testing a very simple VIP System and it goes compiled no Errors no mistakes nothing wrong all thing fine.

But when i go ingame to test it look what happened:



Here's code:
PHP код:
#define FILTERSCRIPT
//Credits to samp
#include <a_samp>
//Credits to Zeex for zcmd
#include <zcmd>
//Credits to ****** for foreach
#include <foreach>
//Credits to ****** for sscanf
#include <sscanf>
#include <dini>
//Credits to me folor colors
#define COLOR_RED 0xF00F00
#define COLOR_GREEN 0xFF000FFF
#define MAX_VIP 3
#define PlayerFile "Vip/%s.ini"
#pragma tabsize 0
enum dData
{
   
Vip
}
new 
PlayerInfo[MAX_PLAYERS][dData];
public 
OnFilterScriptInit()
{
    print(
"\n--------------------------------------");
    print(
"Vip system loaded!");
    print(
"--------------------------------------\n");
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
       new 
file[256], name[MAX_PLAYER_NAME];
       
GetPlayerName(playerid,name,sizeof(name));
       
format(file,sizeof(file),PlayerFile,name);
       if(!
dini_Exists(file) )
       {
             
dini_Create(file);
             
dini_Set(file,"Name",name);
             
dini_IntSet(file,"Vip",0);
             
PlayerInfo[playerid][Vip] = 0;
             
SendClientMessage(playerid,COLOR_RED,"Your vip level is 0; !");
       }
       else
       {
              
PlayerInfo[playerid][Vip] = dini_Int(file,"Vip");
              new 
string[256];
              
format(string,sizeof(string),"Your vip level is %d",PlayerInfo[playerid][Vip]);
              
SendClientMessage(playerid,COLOR_GREEN,string);
       }
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
      new 
file[256], name[MAX_PLAYER_NAME];
       
GetPlayerName(playerid,name,sizeof(name));
       
format(file,sizeof(file),PlayerFile,name);
       if(
dini_Exists(file) )
       {
            
dini_IntSet(file,"Vip",PlayerInfo[playerid][Vip]);
       }
    return 
1;
}
public 
OnPlayerSpawn(playerid)
{
    return 
1;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    return 
1;
}
public 
OnPlayerText(playeridtext[])
{
     if(
text[0] == '!' )
     {
           if(
PlayerInfo[playerid][Vip] > 0)
           {
              new 
name[MAX_PLAYER_NAME];
              
GetPlayerName(playerid,name,sizeof(name));
               new 
string[256];
               
format(string,sizeof(string),"Vip -- %s ( rank: %d): %s",name,PlayerInfo[playerid][Vip],text[0]);
               
MessageToVips(COLOR_GREEN,string);
               return 
0;
           }
     }
    return 
1;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
    return 
0;
}
CMD:setvip(playerid,params[])
{
   new 
idlevel;
   if(
sscanf(params,"ud",id,level) ) return SendClientMessage(playerid,COLOR_RED,"USUAGE: /setvip [id][ level]");
    if(!
IsPlayerAdmin(playerid) ) return SendClientMessage(playerid,COLOR_RED,"You are not an admin!");
    if(
level MAX_VIP) return SendClientMessage(playerid,COLOR_RED,"Invalid Level");
     if(!
IsPlayerConnected(id) ) return SendClientMessage(playerid,COLOR_RED,"Player is not connected");
     else
     {
                 new 
name[MAX_PLAYER_NAME], playername[MAX_PLAYER_NAME];
                 
GetPlayerName(playerid,name,sizeof(name));
                 
GetPlayerName(id,playername,sizeof(playername));
                 new 
fstring[256], zstring[256];
                  
format(fstring,sizeof(fstring),"Administrator %s maked you V.I.P level %d",name,level);
                  
format(zstring,sizeof(zstring),"You maked %s level %d",playername,level);
                  
SendClientMessage(playerid,COLOR_RED,zstring);
                  
SendClientMessage(id,COLOR_RED,fstring);
                  
PlayerInfo[id][Vip] = level;
     }
  return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    return 
1;
}
public 
OnPlayerClickPlayer(playeridclickedplayeridsource)
{
    return 
1;
}
//mesage to vips
stock MessageToVips(color, const string[])
{
   foreach(
Player,i)
   {
          if(
IsPlayerConnected(i) == 1)
          if(
PlayerInfo[i][Vip] >= 1)
          
SendClientMessage(i,color,string);
   }




Re: Scripting Help - SoLetsGO - 30.12.2016

This is really strange. Create a temporary variable (tempVar) assign it to 1 and put it in the format command to see if the the problem is about the formatting. After you used sscanf, print out the level. Maybe we can get some information then:
PHP код:
CMD:setvip(playerid,params[])
{
   new 
idlevel;
   if(
sscanf(params,"ud",id,level) ) return SendClientMessage(playerid,COLOR_RED,"USUAGE: /setvip [id][ level]");
   
printf("level : %i",level);
    if(!
IsPlayerAdmin(playerid) ) return SendClientMessage(playerid,COLOR_RED,"You are not an admin!");
    if(
level MAX_VIP) return SendClientMessage(playerid,COLOR_RED,"Invalid Level");
     if(!
IsPlayerConnected(id) ) return SendClientMessage(playerid,COLOR_RED,"Player is not connected");
     else
     {
                 new 
name[MAX_PLAYER_NAME], playername[MAX_PLAYER_NAME];
                 
GetPlayerName(playerid,name,sizeof(name));
                 
GetPlayerName(id,playername,sizeof(playername));
                 new 
fstring[256], zstring[256];
                  new 
tempVar 1;
                  
format(fstring,sizeof(fstring),"Administrator %s maked you V.I.P level %d",name,tempVar);
                  
format(zstring,sizeof(zstring),"You maked %s level %d",playername,tempVar);
                  
SendClientMessage(playerid,COLOR_RED,zstring);
                  
SendClientMessage(id,COLOR_RED,fstring);
                  
PlayerInfo[id][Vip] = level;
     }
  return 
1;




Re: Scripting Help - BiosMarcel - 30.12.2016

Here , made the code less ugly, seems right tho, do what "SoLetsGO" said and print level to check if it is right.


PHP код:
CMD:setvip(playerid,params[]) 

    new 
targetIdlevel
    if(
sscanf(params,"ud"targetIdlevel) ) return SendClientMessage(playerid,COLOR_RED,"USUAGE: /setvip [id][ level]"); 
    if(!
IsPlayerAdmin(playerid) ) return SendClientMessage(playerid,COLOR_RED,"You are not an admin!"); 
    if(
level MAX_VIP) return SendClientMessage(playerid,COLOR_RED,"Invalid Level."); 
    if(!
IsPlayerConnected(targetId) ) return SendClientMessage(playerid,COLOR_RED,"Player is not connected."); 
    new 
adminName[MAX_PLAYER_NAME], targetName[MAX_PLAYER_NAME]; 
    
GetPlayerName(playeridadminNamesizeof(adminName)); 
    
GetPlayerName(targetIdtargetNamesizeof(targetName)); 
    new 
targetMessage[90], adminMessage[70]; 
    
format(targetMessage,sizeof(targetMessage),"Administrator %s has set your V.I.P level to %d."namelevel); 
    
format(adminMessage,sizeof(adminMessage),"You have set %s's V.I.P level %d."targetNamelevel); 
    
SendClientMessage(playerid,COLOR_RED,adminMessage); 
    
SendClientMessage(targetId,COLOR_RED,targetMessage); 
    
PlayerInfo[targetId][Vip] = level
    return 
1;   




Re: Scripting Help - SoLetsGO - 30.12.2016

I see you do not use sscanf2 but just sscanf.
Try updating your sscanf.
It might be that "u" came with sscanf version 2.


Re: Scripting Help - KillerStrike23 - 30.12.2016

do you have a set level command in your gm if u do please post here.


Re: Scripting Help - BiosMarcel - 30.12.2016

Quote:
Originally Posted by SoLetsGO
Посмотреть сообщение
I see you do not use sscanf2 but just sscanf.
Try updating your sscanf.
It might be that "u" came with sscanf version 2.
he might just have renamed the file tho, thats what i did at least


Re: Scripting Help - SoLetsGO - 30.12.2016

Quote:
Originally Posted by [Bios]Marcel
Посмотреть сообщение
he might just have renamed the file tho, thats what i did at least
I guess it's a pretty good explanation why his command didn't work so I don't think it's just renamed ^^


Re: Scripting Help - BiosMarcel - 30.12.2016

Quote:
Originally Posted by SoLetsGO
Посмотреть сообщение
I guess it's a pretty good explanation why his command didn't work so I don't think it's just renamed ^^
Would kind of suprise me if anyone rly had such an old version ... would be a shame , just my humble opinion


Re: Scripting Help - RyderX - 30.12.2016

Quote:
Originally Posted by SoLetsGO
Посмотреть сообщение
I see you do not use sscanf2 but just sscanf.
Try updating your sscanf.
It might be that "u" came with sscanf version 2.
Tried and failed.
Between it's working fine now thanks guys a lot for helping!


Re: Scripting Help - RyderX - 30.12.2016

Sorry for being annoying as hell, i have 1 more question:
i can't Demote the player which i've promote him any Suggestion?