Help in my Skill system
#1

Hello,
I'm working on a FS with Skill system. If you have kill X or + players, he give at spawn one or two or three more weapons...

Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <a_samp> // This includes a_samp from pawno/include/
#include <Dini>      // This include is use for saving data's
#include <Dutils>   // This include is used for some important function
#include <Dudb>   //  This include is used for hashing password

#define COLOR_RED   0xFF0000FF
#define COLOR_BLUE   0x0004FFFF
#define COLOR_GREEN   0x00FF55FF
#define COLOR_YELLOW   0xEAFF00FF
#define COLOR_ORANGE   0xFFB300FF
#define COLOR_BLACK   0x000000FF
#define COLOR_WHITE   0xFFFFFFFF

#define savefolder "/skills/%s.ini" // This defines the file name and folder

#pragma unused ret_memcpy // This avoid the ret_memcpy warning

new Killz[MAX_PLAYERS];       // We have used this variable because to save the kills of the player
new Skillz_Weap[MAX_PLAYERS];  // Same on here

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Blank Filterscript by your name here");
	print("--------------------------------------\n");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

#else

main()
{
	print("\n----------------------------------");
	print(" Blank Gamemode by your name here");
	print("----------------------------------\n");
}

#endif

public OnPlayerRequestClass(playerid, classid)
{
	return 1;
}

public OnPlayerConnect(playerid)
{
    new pname[128];  // This get's the length of the player name
    new file[128];        // This get's the lenght of the file
    GetPlayerName(playerid, pname, sizeof(pname)); // This get's the player name with the lenght of the player name
    format(file, sizeof(file), savefolder,pname); // This describe's where to save and how to save it
    if(!dini_Exists(file)) { // If the file exist
        dini_Create(file); // Create the file
        dini_IntSet(file, "Kills", Killz[playerid]); // Set's "Kills"
        dini_IntSet(file, "Skill_Weap", Skillz_Weap[playerid]); // Set's "Skill_Weap"
        // and at last this set's the value which were on the file
    }
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new pname[128]; // The name length
    new file[128]; // The file length
    GetPlayerName(playerid, pname, sizeof(pname)); //  This get's the player name with the name length
    format(file, sizeof(file), savefolder,pname); // Formatting file
    if(!dini_Exists(file)) { // If the file exist
    }
    else
	{ // if not
        dini_IntSet(file, "Kills", Killz[playerid]);  // This get the kills
        dini_IntSet(file, "Skill_Weap", Skillz_Weap[playerid]); // This get the Skill_Weap
    }
	return 1;
}

public OnPlayerSpawn(playerid)
{
    if(Killz[MAX_PLAYERS]>=10)
    {
        Skillz_Weap[playerid] ++;
		GivePlayerWeapon(playerid,28,500);// The death value will be increased
        if(Killz[MAX_PLAYERS]>=20)
        {
             Skillz_Weap[playerid] ++; // The death value will be increased
             if(Killz[MAX_PLAYERS]>=30)
             {
                   Skillz_Weap[playerid] ++; // The death value will be increased
			 }
		}
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    Killz[killerid] ++; // The killer value will be increased
	return 1;
}

public OnVehicleSpawn(vehicleid)
{
	return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
	return 1;
}

public OnPlayerText(playerid, text[])
{
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
	return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
	return 1;
}

public OnRconCommand(cmd[])
{
	return 1;
}

public OnPlayerRequestSpawn(playerid)
{
	return 1;
}

public OnObjectMoved(objectid)
{
	return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
	return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
	return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
	return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
	return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
	return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
	return 1;
}

public OnPlayerExitedMenu(playerid)
{
	return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
	return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
	return 1;
}

public OnPlayerUpdate(playerid)
{
	return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
	return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
	return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
	return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
	return 1;
}
this is my pawn code but if i compile do thir error...:

Код:
C:\Users\Vincenzo\Desktop\M3 SAMP\filterscripts\Skills_1.0.pwn(90) : error 032: array index out of bounds (variable "Killz")
C:\Users\Vincenzo\Desktop\M3 SAMP\filterscripts\Skills_1.0.pwn(94) : error 032: array index out of bounds (variable "Killz")
C:\Users\Vincenzo\Desktop\M3 SAMP\filterscripts\Skills_1.0.pwn(97) : error 032: array index out of bounds (variable "Killz")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
help me pls
Reply
#2

You can't use Killz[MAX_PLAYERS] - probably you want use Killz[playerid].
Reply
#3

Try to remove
PHP код:
[MAX_PLAYERS
of the lines 90, 94 and 97
I think these are the lines in
PHP код:
public OnPlayerSpawn(playerid
PHP код:
    if(Killz[MAX_PLAYERS]>=10
line 90


PHP код:
      if(Killz[MAX_PLAYERS]>=20
line 94


PHP код:
 if(Killz[MAX_PLAYERS]>=30
line 97

or just replace them with
PHP код:
[playerid
Reply
#4

why not?
Reply
#5

playerid represents an index for the array and when you do:
pawn Код:
new Killz[MAX_PLAYERS];
// MAX_PLAYERS is 500
The valid indexes are 0-499. By using Killz[MAX_PLAYERS] for checking/settings values is going out of bounds because the last valid index is 499 and not 500.
Reply
#6

I've fix it thx
Reply
#7

hello again guys... i had try the FS but if i join it not give me weapons at spawn, every time i join the server the file of my name on scriptfiles reset... why?

Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <a_samp> // This includes a_samp from pawno/include/
#include <Dini>      // This include is use for saving data's
#include <Dutils>   // This include is used for some important function
#include <Dudb>   //  This include is used for hashing password

#define COLOR_RED   0xFF0000FF
#define COLOR_BLUE   0x0004FFFF
#define COLOR_GREEN   0x00FF55FF
#define COLOR_YELLOW   0xEAFF00FF
#define COLOR_ORANGE   0xFFB300FF
#define COLOR_BLACK   0x000000FF
#define COLOR_WHITE   0xFFFFFFFF

#define savefolder "/skills/%s.ini" // This defines the file name and folder

#pragma unused ret_memcpy // This avoid the ret_memcpy warning

new Killz[MAX_PLAYERS];       // We have used this variable because to save the kills of the player
new Skillz_Weap[MAX_PLAYERS];  // Same on here

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Blank Filterscript by your name here");
	print("--------------------------------------\n");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

#else

main()
{
	print("\n----------------------------------");
	print(" Blank Gamemode by your name here");
	print("----------------------------------\n");
}

#endif

public OnPlayerRequestClass(playerid, classid)
{
	return 1;
}

public OnPlayerConnect(playerid)
{
    new pname[128];  // This get's the length of the player name
    new file[128];        // This get's the lenght of the file
    GetPlayerName(playerid, pname, sizeof(pname)); // This get's the player name with the lenght of the player name
    format(file, sizeof(file), savefolder,pname); // This describe's where to save and how to save it
    if(!dini_Exists(file)) { // If the file exist
        dini_Create(file); // Create the file
        dini_IntSet(file, "Kills", Killz[playerid]); // Set's "Kills"
        dini_IntSet(file, "Skill_Weap", Skillz_Weap[playerid]); // Set's "Skill_Weap"
        // and at last this set's the value which were on the file
    }
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new pname[128]; // The name length
    new file[128]; // The file length
    GetPlayerName(playerid, pname, sizeof(pname)); //  This get's the player name with the name length
    format(file, sizeof(file), savefolder,pname); // Formatting file
    if(!dini_Exists(file)) { // If the file exist
    }
    else
	{ // if not
        dini_IntSet(file, "Kills", Killz[playerid]);  // This get the kills
        dini_IntSet(file, "Skill_Weap", Skillz_Weap[playerid]); // This get the Skill_Weap
    }
	return 1;
}

public OnPlayerSpawn(playerid)
{
    if(Killz[playerid]==10)
    {
        Skillz_Weap[playerid] ++;
		// The death value will be increased
        if(Killz[playerid]==20)
        {
             Skillz_Weap[playerid] ++; // The death value will be increased
             if(Killz[playerid]==30)
             {
                   Skillz_Weap[playerid] ++;
				   GivePlayerWeapon(playerid,35,20); // The death value will be increased
			 }
		}
	}
	if(Skillz_Weap[playerid]>=1)
	{
         GivePlayerWeapon(playerid,42,100);
         if(Skillz_Weap[playerid]>=2)
         {
               GivePlayerWeapon(playerid,39,15);
               if(Skillz_Weap[playerid]==3)
               {
                      GivePlayerWeapon(playerid,35,15);
			   }
		 }
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    Killz[killerid] ++; // The killer value will be increased
	return 1;
}

public OnVehicleSpawn(vehicleid)
{
	return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
	return 1;
}

public OnPlayerText(playerid, text[])
{
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
	return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
	return 1;
}

public OnRconCommand(cmd[])
{
	return 1;
}

public OnPlayerRequestSpawn(playerid)
{
	return 1;
}

public OnObjectMoved(objectid)
{
	return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
	return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
	return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
	return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
	return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
	return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
	return 1;
}

public OnPlayerExitedMenu(playerid)
{
	return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
	return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
	return 1;
}

public OnPlayerUpdate(playerid)
{
	return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
	return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
	return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
	return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
	return 1;
}
Reply
#8

Use #include <YSI\y_ini> I think is much better than #include <dini>

Here is a tutorial
https://sampforum.blast.hk/showthread.php?tid=297301
Reply
#9

Also, at the starting of the script, there is a line:
pawn Код:
//#define FILTERSCRIPT
Change it to:
pawn Код:
#define FILTERSCRIPT
Because you are making a filterscript.
Reply
#10

Quote:
Originally Posted by BenJackster
Посмотреть сообщение
Also, at the starting of the script, there is a line:
pawn Код:
//#define FILTERSCRIPT
Change it to:
pawn Код:
#define FILTERSCRIPT
Because you are making a filterscript.
Not run... Again... not give weapons at spawn...
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)