SA-MP Forums Archive
Help with making gOwner get updated! - 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: Help with making gOwner get updated! (/showthread.php?tid=614570)



Help with making gOwner get updated! - Jensenn - 09.08.2016

Hello SA:MP Community,
I wanna know how to make the gOwner in my script get updated everytime I use [/makegateowner] so that it shows the gate owner when I use the command [/gused]
Here's my [/makegatowner] code:
Код:
CMD:gused(playerid, params[])
{
	new string[128];
	if(!gPlayerLogged[playerid]) return SendClientMessage(playerid, COLOR_GREY, "To use the commands, you need to login first.");
	if(PlayerInfo[playerid][pAdmin] < 6) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
	SendClientMessage(playerid, COLOR_ORANGE, "[Used Gates]:");
	for(new idx=1; idx<MAX_GATES; idx++)
	{
	    if(GateInfo[idx][gModel])
	    {
			format(string, sizeof(string), "ID: %d | Owner: %s | Object: %d | Speed: %f | Password: %s", idx, GateInfo[idx][gOwner], GateInfo[idx][gModel], GateInfo[idx][gSpeed], GateInfo[idx][gPassword]);
			SendClientMessage(playerid, COLOR_ORANGE, string);
	    }
	}
	return 1;
}
Код:
CMD:makegateowner(playerid, params[])
{
	new giveplayerid, slot, idx, string[128];
	if(!gPlayerLogged[playerid]) return SendClientMessage(playerid, COLOR_GREY, "To use the commands, you need to login first.");
	if(PlayerInfo[playerid][pAdmin] < 6) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command");
	if(sscanf(params, "uii", playerid, slot, idx)) return SendClientMessage(playerid, COLOR_GREEN, "[+]{FFFFFF} /makegateowner [playerid] [slot(1-3)] [gateid]");
	if(!gPlayerLogged[playerid]) return SendClientMessage(playerid, COLOR_GREY, "Suitable non-player ID si.");
	if(idx > 0 && !GateInfo[idx][gModel] || idx < 0) return SendClientMessage(playerid, COLOR_GREY, "Invalid gate ID!");
	if(slot < 1 || slot > 3) return SendClientMessage(playerid, COLOR_GREY, "Gate slots are between 1 and 3.");
	switch(slot)
	{
	    case 1: PlayerInfo[playerid][pGate1] = idx;
	    case 2: PlayerInfo[playerid][pGate2] = idx;
	    case 3: PlayerInfo[playerid][pGate3] = idx;
	}
	if(idx == 0)
	{
		format(string, sizeof(string), "%s admin %d to you deleted gate", GetPlayerNameEx(giveplayerid), slot);
		SendClientMessage(playerid, COLOR_WHITE, string);
		format(string, sizeof(string), "AdminWrong: %s admin %d to you deleted gate", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid), slot);
		SendAdminMessage(COLOR_LIGHTRED, 1, string);
		Log("logs/gates.log", string);
	}
	else
	{
		format(string, sizeof(string), "%s admin %d ID for gate owner you!", GetPlayerNameEx(giveplayerid), idx, slot);
		SendClientMessage(playerid, COLOR_WHITE, string);
		format(string, sizeof(string), "AdminWrong: %s gate owned %s you ID! %d. (Slot %d)", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid), idx, slot);
		SaveGates();
		SendAdminMessage(COLOR_LIGHTRED, 1, string);
		Log("logs/gates.log", string);
	}
	return 1;
}
Thanks for Helping me!


Re: Help with making gOwner get updated! - Shinja - 09.08.2016

Can't understand turkish..
You can make it english version, Only to get help in forums


Re: Help with making gOwner get updated! - Jensenn - 09.08.2016

Quote:
Originally Posted by Shinja
Посмотреть сообщение
Can't understand turkish..
You can make it english version, Only to get help in forums
ok, i changed


Re: Help with making gOwner get updated! - Freaksken - 09.08.2016

You forgot to set GateInfo[idx][gOwner] to a playerid in your /makegateowner command.


Re: Help with making gOwner get updated! - Jensenn - 09.08.2016

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
You forgot to set GateInfo[idx][gOwner] to a playerid in your /makegateowner command.
ty but not working :ı

http://i.hizliresim.com/G3n2a2.png

Код:
enum gateInfo
{
	gGate,
	Text3D:gText,
	gModel,
	Float:gCX,
	Float:gCY,
	Float:gCZ,
	Float:gCRX,
        .
        .
	gOwner,
	gStatus
}
im using gOwner just the enum and cmds in command


Re: Help with making gOwner get updated! - Freaksken - 09.08.2016

Change this
Код:
format(string, sizeof(string), "ID: %d | Owner: %s | Object: %d | Speed: %f | Password: %s", idx, GateInfo[idx][gOwner], GateInfo[idx][gModel], GateInfo[idx][gSpeed], GateInfo[idx][gPassword]);
to this if you want to display the playerid
Код:
format(string, sizeof(string), "ID: %d | Owner: %d | Object: %d | Speed: %f | Password: %s", idx, GateInfo[idx][gOwner], GateInfo[idx][gModel], GateInfo[idx][gSpeed], GateInfo[idx][gPassword]);
or this if you want to display the player name
Код:
if(GateInfo[idx][gOwner] != INVALID_PLAYER_ID) {
    new ownerName[MAX_PLAYER_NAME + 1];
    GetPlayerName(GateInfo[idx][gOwner], ownerName, sizeof(ownerName));
    format(string, sizeof(string), "ID: %d | Owner: %s | Object: %d | Speed: %f | Password: %s", idx, ownerName, GateInfo[idx][gModel], GateInfo[idx][gSpeed], GateInfo[idx][gPassword]);
} else {
    format(string, sizeof(string), "ID: %d | Owner: %s | Object: %d | Speed: %f | Password: %s", idx, "Nobody", GateInfo[idx][gModel], GateInfo[idx][gSpeed], GateInfo[idx][gPassword]);
}
Don't forget to do the following when you first create the object and it doesn't have an owner.
Because of the nature of enums, gOwner could be any value (I can't explain it really well, just initialize gOwner and everything should be fine).
Код:
GateInfo[idx][gOwner] = INVALID_PLAYER_ID;



Re: Help with making gOwner get updated! - Jensenn - 09.08.2016

@Freaksken

thanks mate

but result: http://i.hizliresim.com/J3LA7J.png

Quote:
Originally Posted by Freaksken
Код:
GateInfo[idx][gOwner] = INVALID_PLAYER_ID;
i dont understand here?
i changed /gused;
Код:
CMD:gused(playerid, params[])
{
	new string[128];
	if(!gPlayerLogged[playerid]) return SendClientMessage(playerid, COLOR_GREY, "Komutları kullanmak iзin цnce giriş yapmanız gerekmektedir.");
	if(PlayerInfo[playerid][pAdmin] < 6) return SendClientMessage(playerid, COLOR_GREY, "Bu komutu kullanma yetkiniz yok");
	SendClientMessage(playerid, COLOR_ORANGE, "[Used Gates]:");
	for(new idx=1; idx<MAX_GATES; idx++)
	{
	if(GateInfo[idx][gModel])
	{
	if(GateInfo[idx][gOwner] != INVALID_PLAYER_ID)
	{
	new ownerName[MAX_PLAYER_NAME + 1];
	GetPlayerName(GateInfo[idx][gOwner], ownerName, sizeof(ownerName));
	format(string, sizeof(string), "ID: %d | Owner: %s | Object: %d | Speed: %f | Password: %s", idx, ownerName, GateInfo[idx][gModel], GateInfo[idx][gSpeed], GateInfo[idx][gPassword]);
	}
	else
	{
	format(string, sizeof(string), "ID: %d | Owner: %s | Object: %d | Speed: %f | Password: %s", idx, "Nobody", GateInfo[idx][gModel], GateInfo[idx][gSpeed], GateInfo[idx][gPassword]);
	}
	SendClientMessage(playerid, COLOR_ORANGE, string);
	}
	}
	return 1;
}



Re: Help with making gOwner get updated! - Freaksken - 10.08.2016

Say you have an enum like this:
Код:
//Top of script
enum MY_ENUM {
    SOME_KEY, //This will be initialized to 0
    OTHER_KEY, //This will be initialized to 0
    LAST_KEY //This will be initialized to 0
}
new myVariable[MY_ENUM];

//Somewhere in the script
printf("%d %d %d", myVariable[SOME_KEY], myVariable[OTHER_KEY], myVariable[LAST_KEY]);
The output will be: 0, 0, 0.

So what I mean is, there is a default value of 0 assigned (just like with normal variables).
But since playerids start from ID 0, this has unwanted consequences.
So what you need to do to fix this is to initialize the values to something else.

So when you first create the gate, this happens automatically:
Код:
GateInfo[idx][gOwner] = 0;
But we don't want that, because that means the first player that joins the server will be the owner of that gate.
To fix this, do this when you first create the gate:
Код:
GateInfo[idx][gOwner] = INVALID_PLAYER_ID;



Re: Help with making gOwner get updated! - Jensenn - 10.08.2016

sorry bro i can not
my /creategate
Код:
CMD:creategate(playerid, params[])
{
	new string[128], object;
   	if(!gPlayerLogged[playerid]) return SendClientMessage(playerid, COLOR_GREY, "Komutları kullanmak iзin цnce giriş yapmanız gerekmektedir.");
	if(PlayerInfo[playerid][pAdmin] < 6) return SendClientMessage(playerid, COLOR_GREY, "Bu komutu kullanma yetkiniz yok.");
	if(sscanf(params, "i", object)) return SendClientMessage(playerid, COLOR_GREEN, "[+]{FFFFFF} /creategate [objectid]");
	for(new idx=1; idx<MAX_GATES; idx++)
	{
	    if(!GateInfo[idx][gModel])
	    {
	        GetPlayerPos(playerid, GateInfo[idx][gCX], GateInfo[idx][gCY], GateInfo[idx][gCZ]);
  			GateInfo[idx][gModel] = object;
			GateInfo[idx][gCX] = GateInfo[idx][gCX] + 2;
			GateInfo[idx][gCY] = GateInfo[idx][gCY] + 2;
			GateInfo[idx][gCRX] = 0;
			GateInfo[idx][gCRY] = 0;
			GateInfo[idx][gCRZ] = 0;
			GetPlayerPos(playerid, GateInfo[idx][gOX], GateInfo[idx][gOY], GateInfo[idx][gOZ]);
			GateInfo[idx][gOX] = GateInfo[idx][gOX] + 2;
			GateInfo[idx][gOY] = GateInfo[idx][gOY] + 2;
			GateInfo[idx][gORX] = 0;
			GateInfo[idx][gORY] = 0;
			GateInfo[idx][gORZ] = 0;
			GateInfo[idx][gStatus] = 0;
			format(GateInfo[idx][gPassword], 256, "");
			GateInfo[idx][gSpeed] = 2;
			// Creating
			format(string, sizeof(string), "Gate ID: %d", idx);
			GateInfo[idx][gGate] = CreateDynamicObject(GateInfo[idx][gModel], GateInfo[idx][gCX], GateInfo[idx][gCY], GateInfo[idx][gCZ], GateInfo[idx][gCRX], GateInfo[idx][gCRY], GateInfo[idx][gCRZ]);
			GateInfo[idx][gText] = CreateDynamic3DTextLabel(string, COLOR_WHITE, GateInfo[idx][gCX], GateInfo[idx][gCY], GateInfo[idx][gCZ], 10);
			// Text
			format(string, sizeof(string), "AdminUyarı:%s adlı admin %d id'li gateyi oluşturdu!. (Object: %d)", GetPlayerNameEx(playerid), idx, object);
			SaveGates();
		    SendAdminMessage(COLOR_RED, 1, string);
			Log("logs/gates.log", string);
			idx = MAX_GATES;
		}
	}
	return 1;
}



Re: Help with making gOwner get updated! - Freaksken - 10.08.2016

What don't you understand? Just put the following line in that code if you want the owner to be nobody on creation of the gate.
Код:
GateInfo[idx][gOwner] = INVALID_PLAYER_ID;