SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 04/09/2011, 04:49 PM   #1
samtey
Gangsta
 
samtey's Avatar
 
Join Date: Jul 2011
Posts: 528
Reputation: 20
Default Those businesses...

Hi!

I need your help again! I downloaded that business tutorial, but now I don't know what to do with thos strlen and strcmp...I need your help badly!

PHP Code:
#include <a_samp>

#define MAX_BUSINESSES 100 //Increase if you need more but it will make your script larger.
#define PayoutTimer 60 //Number of seconds before the player gets his next pay.
enum BusInfo
{
    
Float:BusX//Business X Pos
    
Float:BusY,  //Business Y Pos
    
Float:BusZ,  //Business Z Pos
    
BusCost,  //Business buy cost
    
BusSell,  // Business sell cost
    
BusEarn,  //Business earn
    
BusOwner// ID of the player that owns the business
    
BusName[60], // The name of the business
    
Disabled //If the business is disabled or not
};
//Add these at the top of your script.
new BusinessPickup[MAX_BUSINESSES]; // This is for all the pickups for the businesses.
new BusinessCount = -1// This is so we can store all the business info like this BusinessInfo[BusinessCount][BusOwner]
new BusinessInfo[MAX_BUSINESSES][BusInfo]; // All the enum info is saved into one variable.

CreateBusiness(BusinessName[], Float:XPosFloat:YPosFloat:ZPosPriceSellEarn)
{
    if(!
strlen(BusinessName)) return 0//If there is no name then it will not create the business
    
BusinessCount ++; //Adding 1 onto the businesscount so the first one will be  BusinessInfo[0][....]
    
BusinessInfo[BusinessCount][BusX] = XPos//Sets the Xpos into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusY] = YPos//Sets the Ypos into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusZ] = ZPos//Sets the Zpos into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusCost] = Price//Sets the price into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusSell] = Sell//Sets the Sell cost into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusEarn] = Earn// //Sets the earning into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusOwner] = -1//Sets the business owner into the variable for long term saving.
    
BusinessPickup[BusinessCount] = AddStaticPickup(127219XPosYPosZPos, -1); //Adds the pickup
    
format(BusinessInfo[BusinessCount][BusName], 60"%s"BusinessName); //Sets the business name into the variable for long term saving.
    
return BusinessCount//Will return the business ID
}


public 
OnFilterScriptInit() //Change to OnFilterScriptInit if it's a filterscript =].
{
    
SetTimer("Payouttimer"PayoutTimertrue); //Sets the timer =].
       
CreateBusiness("TestBiz"100.0100.010.01333710000100);
    return 
1;
}

stock IsPlayerCloseEnoughToBis(playerid)
{
    for(new 
CC<BusinessCount+1C++)//Loops through all businesses
    
{
        if(
IsPlayerInRangeOfPoint(playerid3BusinessInfo[C][BusX],  BusinessInfo[C][BusY], BusinessInfo[C][BusZ])) return C// Checks if a business is close enough
    
}
    return -
1;
}

forward Payouttimer(); //You must forward a timer
public Payouttimer()
{
    for(new 
ii<GetMaxPlayers(); i++) // Loops through every player
    
{
        if(
GetPVarInt(i"Businessearnings") != 0//Does the player earn any $$
        
{
            new 
Str[100]; // Creating a string
            
format(Strsizeof(Str), "You have earned %d from all your properties!"GetPVarInt(i"Businessearnings")); //Formats the string
            
SendClientMessage(i0x00FF00AAStr); //Sends the string to the player
            
GivePlayerMoney(iGetPVarInt(i"Businessearnings")); //Gives the player the $$
        
}
    }
    return 
1;
}

public 
OnPlayerCommandText(playeridcmdtext[])
{
    if(!
strcmp(cmdtext"/buy"true))
    {
        if(
IsPlayerCloseEnoughToBis(playerid) == -1) return SendClientMessage(playerid0xAA3333AA"You are not close enough to a business!!!"); //Returns this if the player isn't within 3 X, Y or Z of the business
        
new buss IsPlayerCloseEnoughToBis(playerid); //Makes a shorter define
        
if(BusinessInfo[buss][Disabled] == 1) return SendClientMessage(playerid0xAA3333AA"Business is disabled!!"); //This is for a function down at the bottom of this tutorial
        
if(GetPlayerMoney(playerid) < BusinessInfo[buss][BusCost]) return SendClientMessage(playerid0xAA3333AA"You don't have enough money for this business =D"); //Will return this if the player is a poor nub =D.
        
if(BusinessInfo[buss][BusOwner] != -1) return SendClientMessage(playerid0xAA3333AA"Someone already owns this business!"); //Will return it if somebody online owns the business.
        
BusinessInfo[buss][BusOwner] = playerid//Sets the business owner
        
SetPVarInt(playerid"Businessearnings" GetPVarInt(playerid"Businessearnings") + BusinessInfo[buss][BusEarn]); // Makes the players earn more
        
new str[100]; //Creates a string
        
format(strsizeof(str), "You have brought the business %s for $%d. You will now earn $%d",  BusinessInfo[buss][BusName], BusinessInfo[buss][BusCost], BusinessInfo[buss][BusEarn]); //Formats a string
        
SendClientMessage(playerid0x00FF00AAstr); //Sends the string
        
GivePlayerMoney(playerid, -BusinessInfo[buss][BusCost]); //Takes the $$ of for the business
        
return 1;
    }
    if(!
strcmp(cmdtext"/sell"true))
    {
        if(
IsPlayerCloseEnoughToBis(playerid) == -1) return SendClientMessage(playerid0xAA3333AA"You are not close enough to a business!!!"); //Checks if the player is close enough to any business
        
new buss IsPlayerCloseEnoughToBis(playerid); //Shortens the function
        
if(BusinessInfo[buss][BusOwner] != playerid) return SendClientMessage(playerid0xAA3333AA"You don't own this business!"); //Checks if the player actually owns this business
        
BusinessInfo[buss][BusOwner] = -1//Deletes the owner.
        
SetPVarInt(playerid"Businessearnings"GetPVarInt(playerid"Businessearnings") - BusinessInfo[buss][BusEarn]); //Sets the players business earning down.
        
new str[100];//Creates string
        
format(strsizeof(str), "You have sold the business %s for $%d",  BusinessInfo[buss][BusName], BusinessInfo[buss][BusCost]); //Formats a string
        
SendClientMessage(playerid0x00FF00AAstr); //Sends the string.
        
GivePlayerMoney(playeridBusinessInfo[buss][BusSell]); //Gives the player the $$ for selling the business =].
        
return 1;
    }
    return 
0;
}

public 
OnPlayerPickUpPickup(playerid,pickupid//If you have one of these add the stuff in this to your one =]
{
    for(new 
CC<BusinessCount+1C++)//Loops through all businesses
    
{
        if(
pickupid == BusinessPickup[C]) //Checks if the pickup is for a business
        
{
            new 
str[150];//Creates a string.
            
if(BusinessInfo[C][BusOwner] == -1format(strsizeof(str), "%s ~n~~r~Cost price: $%d ~b~Sale price: $%d ~n~ ~g~Earn ammount: $%d"BusinessInfo[C][BusName], BusinessInfo[C][BusCost], BusinessInfo[C][BusSell], BusinessInfo[C][BusEarn]); //Makes the string for a business with no owner.
            
if(BusinessInfo[C][BusOwner] != -1)
            {
                new 
Pname[24]; //Creates player name variable
                
GetPlayerName(BusinessInfo[C][BusOwner], Pname24); //Gets player name
                
format(strsizeof(str), "%s ~n~~r~Cost price: $%d ~b~Sale price: $%d ~n~ ~g~Earn ammount: $%d~n~~w~Owner: %s(%d)"BusinessInfo[C][BusName], BusinessInfo[C][BusCost], BusinessInfo[C][BusSell], BusinessInfo[C][BusEarn], PnameBusinessInfo[C][BusOwner]);
                
GameTextForPlayer(playeridstr30003);
            }
        }
    }
    return 
1;
}

public 
OnPlayerDisconnect(playerid//Copy the stuff below into your one if you have one =D.
{
    for(new 
CC<BusinessCount+1C++)//Loops through all businesses
    
{
        if(
BusinessInfo[C][BusOwner] == playerid)  BusinessInfo[C][BusOwner] = -1//Deletes the owner.
    
}
    return 
1;
}

stock ChangeBusinessName(BusinessIDBusNamme)
{
    
format(BusinessInfo[BusinessID][BusName], 60"%s"BusNamme);
    return 
1;
}

stock DisableBusiness(BusinessID)
{
    
BusinessInfo[BusinessID][Disabled] = 1;
    return 
1;
}

stock EnableBusiness(BusinessID)
{
    
BusinessInfo[BusinessID][Disabled] = 0;
    return 
1;
}

stock DeleteBusinessOwner(BusinessID)
{
    
BusinessInfo[BusinessID][BusOwner] = -1;
    return 
1;
}

stock ChangeBusinessCost(BusinessIDBussCost)
{
    
BusinessInfo[BusinessID][BusCost] = BussCost;
    return 
1;
}

stock ChangeBusinessSell(BusinessIDBussSell)
{
    
BusinessInfo[BusinessID][BusSell] = BussSell;
    return 
1;
}

stock ChangeBusinessEarn(BusinessIDEarrn)
{
    
BusinessInfo[BusinessID][BusEarn] = Earrn;

Of course, you will deserve your rep (then you don't beg anymore, I hope) because this is a little long! I am using ZCMD, this is my problem!

Also, I don't know how to create businesses... Make the co-ordinates, sure, but where in the script should I put it?
Thanks!
__________________
Dear USER! If I helped you in one of your posts, then please give me reputation! I also will give you if you help me!

samtey is offline   Reply With Quote
Old 04/09/2011, 04:52 PM   #2
Darnell
Gangsta
 
Darnell's Avatar
 
Join Date: Jul 2010
Posts: 824
Reputation: 35
Default Re: Those businesses...

http://forum.sa-mp.com/showthread.php?t=280387
http://forum.sa-mp.com/showthread.php?t=280282
Darnell is offline   Reply With Quote
Old 04/09/2011, 04:59 PM   #3
samtey
Gangsta
 
samtey's Avatar
 
Join Date: Jul 2011
Posts: 528
Reputation: 20
Default AW: Those businesses...

Thanks!

But I don't understand the conversation of strlen...

Also, my second question:

Quote:
Also, I don't know how to create businesses... Make the co-ordinates, sure, but where in the script should I put it?
Thanks!
__________________
Dear USER! If I helped you in one of your posts, then please give me reputation! I also will give you if you help me!

samtey is offline   Reply With Quote
Old 04/09/2011, 05:07 PM   #4
Darnell
Gangsta
 
Darnell's Avatar
 
Join Date: Jul 2010
Posts: 824
Reputation: 35
Default Re: Those businesses...

Try this one aswell.
http://forum.sa-mp.com/showthread.php?t=176372
Darnell is offline   Reply With Quote
Old 04/09/2011, 05:45 PM   #5
samtey
Gangsta
 
samtey's Avatar
 
Join Date: Jul 2011
Posts: 528
Reputation: 20
Default AW: Those businesses...

I still don't understand it! Why can't you just convert this one for me as an example

Also, my other question still needs an answer!
__________________
Dear USER! If I helped you in one of your posts, then please give me reputation! I also will give you if you help me!

samtey is offline   Reply With Quote
Old 05/09/2011, 06:40 AM   #6
samtey
Gangsta
 
samtey's Avatar
 
Join Date: Jul 2011
Posts: 528
Reputation: 20
Default AW: Those businesses...

Please help me!
__________________
Dear USER! If I helped you in one of your posts, then please give me reputation! I also will give you if you help me!

samtey is offline   Reply With Quote
Old 05/09/2011, 06:45 AM   #7
Lorenc_
High-roller
 
Lorenc_'s Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 3,793
Reputation: 1179
Default Re: Those businesses...

strlen = strings length

pawn Code:
new string[12] = "12345678910";
printf("String: %s", string);
printf("String Length: %d", strlen(string));
__________________
Join the best Cops And Robbers in SA-MP, today. svr.sfcnr.com:7777

Lorenc_ is offline   Reply With Quote
Old 05/09/2011, 06:46 AM   #8
[MWR]Blood
High-roller
 
Join Date: Apr 2009
Posts: 2,268
Reputation: 105
Default Re: Those businesses...

pawn Code:
if(!strcmp(cmdtext, "/buy", true))
This one becomes
pawn Code:
CMD:buy(playerid, params[])
for ZCMD.

About creating the businesses, most likely you have a text file in your scriptfiles directory that contains the coordinates of all the businesses.
[MWR]Blood is offline   Reply With Quote
Old 05/09/2011, 06:56 AM   #9
samtey
Gangsta
 
samtey's Avatar
 
Join Date: Jul 2011
Posts: 528
Reputation: 20
Default AW: Re: Those businesses...

Quote:
Originally Posted by Lorenc_ View Post
strlen = strings length

pawn Code:
new string[12] = "12345678910";
printf("String: %s", string);
printf("String Length: %d", strlen(string));
I know what it is for, but how to convert it here??

PHP Code:
CreateBusiness(BusinessName[], Float:XPosFloat:YPosFloat:ZPosPriceSellEarn)
{
    if(!
strlen(BusinessName)) return 0//If there is no name then it will not create the business
    
BusinessCount ++; //Adding 1 onto the businesscount so the first one will be  BusinessInfo[0][....]
    
BusinessInfo[BusinessCount][BusX] = XPos//Sets the Xpos into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusY] = YPos//Sets the Ypos into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusZ] = ZPos//Sets the Zpos into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusCost] = Price//Sets the price into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusSell] = Sell//Sets the Sell cost into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusEarn] = Earn// //Sets the earning into the variable for long term saving.
    
BusinessInfo[BusinessCount][BusOwner] = -1//Sets the business owner into the variable for long term saving.
    
BusinessPickup[BusinessCount] = AddStaticPickup(127219XPosYPosZPos, -1); //Adds the pickup
    
format(BusinessInfo[BusinessCount][BusName], 60"%s"BusinessName); //Sets the business name into the variable for long term saving.
    
return BusinessCount//Will return the business ID
}


public 
OnFilterScriptInit() //Change to OnFilterScriptInit if it's a filterscript =].
{
    
SetTimer("Payouttimer"PayoutTimertrue); //Sets the timer =].
       
CreateBusiness("TestBiz"100.0100.010.01333710000100);
    return 
1;


@Blood

Where to put it's co-ordinates??
__________________
Dear USER! If I helped you in one of your posts, then please give me reputation! I also will give you if you help me!

samtey is offline   Reply With Quote
Old 05/09/2011, 07:00 AM   #10
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 2,629
Reputation: 410
Default Re: Those businesses...

That's my really old tutorial (Mid 2010). I'll remake it in a few weeks, currently I have exams. The way you create businesses is like this:

pawn Code:
CreateBusiness(BusinessName[], Float:XPos, Float:YPos, Float:ZPos, Price, Sell, Earn)
/*
BusinessName - The business name
XPos - The X position of the business.
YPos - The Y position of the business.
ZPos - The Z position of the business
price - Cost price of the business
sell - Sell price of the business
earn - The cash you earn from the business
*/

You need to put that on OnFilterScriptInit or OnGameModeInit.
__________________
[HiC]TheKiller 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
businesses SpiderWalk Help Archive 2 28/04/2011 11:15 AM
[FilterScript] Businesses!!! darkknight123 Filterscripts 2 25/01/2011 04:29 PM
HELP Businesses ZmaXy Help Archive 5 03/11/2010 01:21 PM
Businesses qwqwqw Help Archive 2 10/05/2010 02:12 AM


All times are GMT. The time now is 04:57 PM.


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