SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 01/11/2017, 09:59 AM   #1
Maky184
Little Clucker
 
Join Date: Oct 2017
Location: Hrvatska
Posts: 23
Reputation: 0
Default JobSkin

How to make /equipment and that when I go again /equipment to give me back the old skin?
Maky184 is offline   Reply With Quote
Old 01/11/2017, 10:11 AM   #2
Arbico
Big Clucker
 
Arbico's Avatar
 
Join Date: Jul 2017
Posts: 84
Reputation: 5
Default Re: JobSkin

You need to save the old skin in the player database
Here is an example. Don't forget to edit it.
PHP Code:
#define Skin 30 //This is the skin you want the player to change to when he enters the command

new OldSkin[MAX_PLAYERS];
new 
Equipped[MAX_PLAYERS] = false;

CMD:equipment(playeridparams[]) {
    if(
Equipped[playerid] == true) {
        
SendClientMessage(playerid0x005500AA"You have returned to your old clothes");
        
SetPlayerSkin(playeridOldSkin[playerid]);
        
Equipped[playerid] = false;
    }
    else {
        
Equipped[playerid] = true;
        
OldSkin[playerid] = GetPlayerSkin(playerid);
        
SendClientMessage(playerid0x005500AA"You have changed your clothes");
        
SetPlayerSkin(playeridSkin);
    }
    return 
1;

__________________
Skype:Arbico
Anywhere, Anytime, i'm here to help.

Arbico is offline   Reply With Quote
Old 01/11/2017, 11:23 AM   #3
Maky184
Little Clucker
 
Join Date: Oct 2017
Location: Hrvatska
Posts: 23
Reputation: 0
Default Re: JobSkin

Tnx but....
(203) warning 213: tag mismatch

(203) if(Equipped[playerid] == true)
Maky184 is offline   Reply With Quote
Old 01/11/2017, 11:26 AM   #4
n00blek
Huge Clucker
 
Join Date: Aug 2017
Location: England is my city
Posts: 242
Reputation: 18
Default Re: JobSkin

Change true to 1
__________________
RMTeam Roleplay! Under construction.

192.168.64.100:7777

PM me for donations(not money, script commands)
n00blek is offline   Reply With Quote
Old 01/11/2017, 01:06 PM   #5
CXdur
Big Clucker
 
CXdur's Avatar
 
Join Date: Jun 2014
Location: Norway
Posts: 57
Reputation: 6
Default Re: JobSkin

Quote:
Originally Posted by Arbico View Post
You need to save the old skin in the player database
Here is an example. Don't forget to edit it.
PHP Code:
#define Skin 30 //This is the skin you want the player to change to when he enters the command

new OldSkin[MAX_PLAYERS];
new 
Equipped[MAX_PLAYERS] = false;

CMD:equipment(playeridparams[]) {
    if(
Equipped[playerid] == true) {
        
SendClientMessage(playerid0x005500AA"You have returned to your old clothes");
        
SetPlayerSkin(playeridOldSkin[playerid]);
        
Equipped[playerid] = false;
    }
    else {
        
Equipped[playerid] = true;
        
OldSkin[playerid] = GetPlayerSkin(playerid);
        
SendClientMessage(playerid0x005500AA"You have changed your clothes");
        
SetPlayerSkin(playeridSkin);
    }
    return 
1;

You should probably distinguish arrays from databases. Arrays are a way to represent structured data in memory. Databases are a tool to store data on disk until you need to retrieve it.

If you'd like to use true/false instead of 0/1, you need to tag the variable with bool:, for instance (boolkinChanged)

Also, the entire equipped variable is obsolete, you can simply use the OldSkin[playerid] variable for this (check if it's set, if not set it, you get the point).

Also, you should probably then reset the OldSkin[playerid] when the player disconnects or connects.

I created a small quick command so you can change to a skin you want, I haven't tested it though:

If you'd like to add this, you need to add SetPVarInt(playerid, "old_skin", -1); to OnPlayerConnect,
if not it will not work properly (this is because CJ has skin 0).

Code:
CMD:equipment(playerid, params[])
{
	new oldSkin = GetPVarInt(playerid, "old_skin");
	if (oldSkin < 0)
	{
		new skin;
		if (sscanf(params, "d", skin))
		{
			return SendClientMessage(playerid, -1, "Usage: {595252}/equipment (skin)");
		}
		else
		{
			if (skin == 65 || skin == 74 || skin < 0 || skin >= 312)
			{
				return SendClientMessage(playerid, -1, "The skin you specified is invalid!");
			}
			
			SetPVarInt(playerid, "old_skin", GetPlayerSkin(playerid));

			SetPlayerSkin(playerid, skin);
		}
	}
	else
	{
		SetPlayerSkin(playerid, oldSkin);
		DeletePVar(playerid, "old_skin");
	}

	return 1;
}
You should be able to understand how to do it from mine and Arbico's code now.

Last edited by CXdur; 04/12/2019 at 12:12 PM. Reason: fixed typo
CXdur is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 02:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.