SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 19/02/2015, 09:11 PM   #11
Alvin007
Huge Clucker
 
Alvin007's Avatar
 
Join Date: Mar 2011
Location: Tunisia
Posts: 245
Reputation: 9
Default Re : Creating a function

PHP Code:
ChangeBizInfo(bizid,playerid,bizname[128])
{
    new 
string[300];
    
BusinessInfo[bizid][bName] = bizname;
    
format(string,sizeof(string),"{FF0000}SERVER:{FFFFFF} You successfully changed your business bizname id [%i], to %s",bizid,bizname);
    
SendClientMessage(playeridYELLOWstring);
    
SaveBusiness(bizid);
    new 
salemsg[100],total[400],thestring[260],lockmsg[40];
    if(
BusinessInfo[bizid][bPrice]>-1format(salemsg,sizeof(salemsg),"[{009ACD}FOR SALE{FFFFFF}]\t {009ACD}Price:{FFFFFF} %i\n",BusinessInfo[bizid][bPrice]);
    else 
format(salemsg,sizeof(salemsg)," ");
    if(
BusinessInfo[bizid][bOwned]==1format(thestring,sizeof(thestring),"{009ACD}Name:{FFFFFF} %s \n {009ACD}Owner:{FFFFFF} %s \n ID: %d",bizname,BusinessInfo[bizid][bOwner],bizid);
    else 
format(thestring,sizeof(thestring),"{009ACD}Name:{FFFFFF} %s \n {009ACD}Owner:{FFFFFF} None \n ID: %d",bizname,bizid);
    if(
BusinessInfo[bizid][bLocked]==1format(lockmsg,sizeof(lockmsg),"[{009ACD}CLOSED{FFFFFF}]\n");
    else 
format(lockmsg,sizeof(lockmsg),"[{009ACD}OPEN{FFFFFF}]\n");
    
format(total,sizeof(total),"%s %s %s",salemsg,lockmsg,thestring);
    
Delete3DTextLabel(BizLabel[bizid]);
    
Create3DTextLabel(total,COLOR_WHITE,BusinessInfo[bizid][bEntranceX], BusinessInfo[bizid][bEntranceY], BusinessInfo[bizid][bEntranceZ],5.0BusinessInfo[bizid][bWorld]);
    return 
1;

Here is my function.
__________________
Alvin007 is offline   Reply With Quote
Old 19/02/2015, 09:16 PM   #12
CalvinC
High-roller
 
CalvinC's Avatar
 
Join Date: Nov 2014
Location: Denmark
Posts: 1,831
Reputation: 114
Default Re: Creating a function

The way you use it:
pawn Code:
ChangeBizInfo(id,BusinessInfo[id][bName],playerid);
Doesn't match with the parameters:
pawn Code:
ChangeBizInfo(bizid,playerid,bizname[128])
You should use it like this:
pawn Code:
ChangeBizInfo(id,playerid,BusinessInfo[id][bName]);

And i don't think it's necessary to use "bizname[128]", you could just use "bizname[]", might be wrong though, haven't tried that.
__________________
[Tutorial] Custom Playerdamage system
Desert Eagle's dealing too much damage, you want one-hit sniper kills, or damage based on body parts? Check this out.
CalvinC is offline   Reply With Quote
Old 19/02/2015, 09:26 PM   #13
Alvin007
Huge Clucker
 
Alvin007's Avatar
 
Join Date: Mar 2011
Location: Tunisia
Posts: 245
Reputation: 9
Default Re : Creating a function

Yeah i know, the code above is after the update, cuz the first one answering me told me that you must put the "integer then string then float"
So it goes like this:
PHP Code:
ChangeBizInfo(bizid,playerid,bizname[128])
{
    new 
string[300];
    
BusinessInfo[bizid][bName] = bizname;
    
format(string,sizeof(string),"{FF0000}SERVER:{FFFFFF} You successfully changed your business bizname id [%i], to %s",bizid,bizname);
    
SendClientMessage(playeridYELLOWstring);
    
SaveBusiness(bizid);
    new 
salemsg[100],total[400],thestring[260],lockmsg[40];
    if(
BusinessInfo[bizid][bPrice]>-1format(salemsg,sizeof(salemsg),"[{009ACD}FOR SALE{FFFFFF}]\t {009ACD}Price:{FFFFFF} %i\n",BusinessInfo[bizid][bPrice]);
    else 
format(salemsg,sizeof(salemsg)," ");
    if(
BusinessInfo[bizid][bOwned]==1format(thestring,sizeof(thestring),"{009ACD}Name:{FFFFFF} %s \n {009ACD}Owner:{FFFFFF} %s \n ID: %d",bizname,BusinessInfo[bizid][bOwner],bizid);
    else 
format(thestring,sizeof(thestring),"{009ACD}Name:{FFFFFF} %s \n {009ACD}Owner:{FFFFFF} None \n ID: %d",bizname,bizid);
    if(
BusinessInfo[bizid][bLocked]==1format(lockmsg,sizeof(lockmsg),"[{009ACD}CLOSED{FFFFFF}]\n");
    else 
format(lockmsg,sizeof(lockmsg),"[{009ACD}OPEN{FFFFFF}]\n");
    
format(total,sizeof(total),"%s %s %s",salemsg,lockmsg,thestring);
    
Delete3DTextLabel(BizLabel[bizid]);
    
Create3DTextLabel(total,COLOR_WHITE,BusinessInfo[bizid][bEntranceX], BusinessInfo[bizid][bEntranceY], BusinessInfo[bizid][bEntranceZ],5.0BusinessInfo[bizid][bWorld]);
    return 
1;

Usage of the function:

PHP Code:
CMD:lockbiz(playeridparams[]) // BUG BUG BUG: Make a function to updated Businesses 3dTextLabel
{
    
//new biz=0;
    
new id IsPlayerNearBizEnt(playerid);//Uses the function to find if player is near a biz!
    
if(PlayerInfo[playerid][pBiz]==0) return SendClientMessage(playerid,RED,"{FF0000}SERVER:{FFFFFF} You don't own a business");
    for(new 
i=0;i<=3;i++)
    {
        if(
PlayaInfo[playerid][0][i]==id)
        {
            if(
BusinessInfo[id][bLocked]==1)
            {
                 
BusinessInfo[id][bLocked]=0;
                 
ChangeBizInfo(id,playerid,BusinessInfo[id][bName]);
                 
GameTextForPlayer(playerid"Biz ~g~unlocked!"50003);
             }
            else if(
BusinessInfo[id][bLocked]==0)
            {
                
BusinessInfo[id][bLocked]=1;
                 
GameTextForPlayer(playerid"Biz ~r~locked!"5003);
                 
ChangeBizInfo(id,playerid,BusinessInfo[id][bName]);
             }
        }
    }
    return 
1;

And same errors:

Quote:
C:\Users\moka\Desktop\PROG\03z\gamemodes\test.pwn( 77 : error 047: array sizes do not match, or destination array is too small
C:\Users\moka\Desktop\PROG\03z\gamemodes\test.pwn( 785) : error 047: array sizes do not match, or destination array is too small
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


2 Errors.
Line 778 and 785 are the lines having: ChangeBizInfo(id,playerid,BusinessInfo[id][bName]);
__________________
Alvin007 is offline   Reply With Quote
Old 19/02/2015, 11:03 PM   #14
Jefff
Banned
 
Join Date: Dec 2007
Posts: 2,594
Reputation: 326
Default Re: Creating a function

Remove 128 from ChangeBizInfo(bizid,playerid,bizname[128]) so ChangeBizInfo(bizid,playerid,bizname[])
Jefff is offline   Reply With Quote
Old 19/02/2015, 11:20 PM   #15
iFiras
Huge Clucker
 
iFiras's Avatar
 
Join Date: Oct 2013
Location: Tunisia
Posts: 489
Reputation: 38
Default Re: Creating a function

The array sizes just need to be the same, make them equal.

Quote:
Originally Posted by Jefff View Post
Remove 128 from ChangeBizInfo(bizid,playerid,bizname[128]) so ChangeBizInfo(bizid,playerid,bizname[])
Or do this. ^
iFiras is offline   Reply With Quote
Old 20/02/2015, 08:04 PM   #16
Alvin007
Huge Clucker
 
Alvin007's Avatar
 
Join Date: Mar 2011
Location: Tunisia
Posts: 245
Reputation: 9
Default Re : Creating a function

It worked thanks, +REP.
__________________
Alvin007 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
Creating a new function Josh_Main Scripting Help 8 29/09/2014 07:15 PM
Need help with creating function Johnson_boy Help Archive 7 24/04/2011 11:35 AM
Creating a function [ Need help ] Cameltoe Help Archive 3 23/08/2010 07:10 PM


All times are GMT. The time now is 03:21 AM.


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