SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 03/04/2013, 03:03 PM   #1
doreto
High-roller
 
doreto's Avatar
 
Join Date: Aug 2010
Posts: 1,667
Reputation: 118
Default weird problem after using random function with array (solved)

So let me first tell you about problem and then show you code. Whole point of problem is that everytime is show me same result over and over and is should be random and only if type (check code below) is 0 (wich is have to be 1) . I've made some debugs on code and even 2 (second line of array ) is chosen (code below) aways print same (first) result.

pawn Code:
//on top

enum mission_unload
{
    name[128],
    type,
    Float:unloadx,
    Float:unloady,
    Float:unloadz

};
new Mission_unload[MAX_PLAYERS][mission_unload];

new unloads[][mission_unload] =
{
    {"LS Construction Site", 0, 1859.0, -1314.0, 14.0}, // Location 1
    {"SF Construction Site", 1, -2083.0, 209.0, 35.5}, // Location 2
    {"LV Construction Site", 1, 2708.0, 878.0, 10.0} // Location 3
    //{"Quarry", 587.25, 844.75, -42.5} // Location 11
};

enum mission_load
{
    names[128],
    type,
    Float:loadx,
    Float:loady,
    Float:loadz
};
new Mission_load[MAX_PLAYERS][mission_load];

new loads[][mission_load]=
{
    {"Quarry", 1, 587.25, 844.75, -42.5}
};

// and command

CMD:work2(playerid, params[])
{
    if(!strcmp(params, "test"))
    {
        new rand = random(sizeof(loads));
        if(loads[rand][type] == 1)
        {
            // random load
            new sload[128];
            format(sload,sizeof(sload),"loads[rand][name] = %s", loads[rand][names]);
            SendClientMessage(playerid, -1, sload);

            SetPlayerCheckpoint(playerid, loads[rand][loadx], loads[rand][loady], loads[rand][loadz],CHECKPOINT_SIZE);
            strset(Mission_load[playerid][names], loads[rand][names]);

            Mission_load[playerid][loadx] = loads[rand][loadx];
            Mission_load[playerid][loady] = loads[rand][loady];
            Mission_load[playerid][loadz] = loads[rand][loadz];
            printf("load name: %s", Mission_load[playerid][names]);
            printf("load - %d",rand);

            // random unload
            new rands = random(sizeof(unloads));
            printf("unload - %d", rands);
            if(unloads[rands][type] == 1)
            {


                new sunload[128];
                format(sunload,sizeof(sunload),"unloads[rand][name] = %s",unloads[rand][name]);
                SendClientMessage(playerid,-1,sunload);



                strset(Mission_unload[playerid][name], unloads[rand][name]);
                Mission_unload[playerid][unloadx] = unloads[rands][unloadx];
                Mission_unload[playerid][unloady] = unloads[rands][unloady];
                Mission_unload[playerid][unloadz] = unloads[rands][unloadz];
                printf("unload name: %s",Mission_unload[playerid][name]);
            }
            else SendClientMessage(playerid,-1,"again - unload");

            new string[128];
            format(string,sizeof(string),"deliver |-_-|> ore form %s to %s",Mission_load[playerid][names],Mission_unload[playerid][name]);
            SendClientMessage(playerid,-1,string);
            cp = 1;
        }
        else SendClientMessage(playerid,-1,"again - load");
    }
    return 1;
}

server log from print function

pawn Code:
[13:44:08] load name: Quarry
[13:44:08] load - 0
[13:44:08] unload - 1
[13:44:08] unload name: LS Construction Site
[13:44:18] load name: Quarry
[13:44:18] load - 0
[13:44:18] unload - 2
[13:44:18] unload name: LS Construction Site
[13:44:19] load name: Quarry
[13:44:19] load - 0
[13:44:19] unload - 1
[13:44:19] unload name: LS Construction Site
[13:44:20] load name: Quarry
[13:44:20] load - 0
[13:44:20] unload - 1
[13:44:20] unload name: LS Construction Site
[13:44:21] load name: Quarry
[13:44:21] load - 0
[13:44:21] unload - 1
[13:44:21] unload name: LS Construction Site

EDIT: i'm sorry forgot to include strset stock
pawn Code:
stock strset(dest[], source[])
{
    new count = strlen(source);
    for(new i = 0; i < count; i++)
    {
        dest[i] = source[i];
    }
    dest[count] = 0;
}


Any type of help will be appreciated!

EDIT:
Problem solved
__________________
Quote:
Originally Posted by Kalcor View Post
This my site, so I get to decide what links are allowed. utube and 1e100 are no longer part of my web of trust.

The internet is more important to me than sa-mp. You don't get sa-mp without the internet.
Quote:
Originally Posted by [Twixx] View Post
That's kind of hypocritical of you to say. Sure you own the website, but it's not your personal blog or something - it's a community driven forum. The community should be the primary focus, not your personal agendas. Just like you don't get SA-MP without internet, you don't get SA-MP forums without community.

Just wiping out years worth of people's work and creations posted on that board because a bunch of people bypassed your Tube ban is absurd.
Quote:
Originally Posted by Mauzen View Post
"tube sucks cause they delete 6 years old videos for no reason!"

*deletes every single video ever posted here in 12 years*

Last edited by doreto; 03/04/2013 at 03:45 PM. Reason: problem solved
doreto is offline   Reply With Quote
Old 03/04/2013, 03:24 PM   #2
SuperViper
High-roller
 
SuperViper's Avatar
 
Join Date: Sep 2011
Posts: 1,178
Reputation: 315
Default Re: weird problem after using random function with array

You're using rand for some of your unload variables while you should be using rands. Let me point out some lines for you:

pawn Code:
format(sunload,sizeof(sunload),"unloads[rand][name] = %s",unloads[rand][name]);

pawn Code:
strset(Mission_unload[playerid][name], unloads[rand][name]);
__________________
Release NameUse
FairPlayKeep the cheaters out of your server
Object Model ArrayArray of every single object model in the game
RCON PanelControl any server as you like with RCON controls
SlopeClimb up a steep hill against other players with cars falling down

I do not play on any SAMP server. Anyone with the name Ricky Phelps in-game is an imposter.
SuperViper is offline   Reply With Quote
Old 03/04/2013, 03:40 PM   #3
doreto
High-roller
 
doreto's Avatar
 
Join Date: Aug 2010
Posts: 1,667
Reputation: 118
Default Re: weird problem after using random function with array

Thank you very much SuperViper , i was aways thing there is something easy and obvious but i was "blind" to see it . You deserve reputation point

EDIT: damm it i was alredy give you reputation point for something that i was find usefull "You must spread some Reputation around before giving it to SuperViper again"



Problem solved
__________________
Quote:
Originally Posted by Kalcor View Post
This my site, so I get to decide what links are allowed. utube and 1e100 are no longer part of my web of trust.

The internet is more important to me than sa-mp. You don't get sa-mp without the internet.
Quote:
Originally Posted by [Twixx] View Post
That's kind of hypocritical of you to say. Sure you own the website, but it's not your personal blog or something - it's a community driven forum. The community should be the primary focus, not your personal agendas. Just like you don't get SA-MP without internet, you don't get SA-MP forums without community.

Just wiping out years worth of people's work and creations posted on that board because a bunch of people bypassed your Tube ban is absurd.
Quote:
Originally Posted by Mauzen View Post
"tube sucks cause they delete 6 years old videos for no reason!"

*deletes every single video ever posted here in 12 years*
doreto 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
Problem with random number function caki Scripting Help 7 02/02/2013 05:48 PM
Random value from array. kLx Help Archive 1 18/03/2011 02:45 PM
[Q] Array Problem Involving random skins [ERP]Snow Help Archive 3 19/07/2009 12:17 PM
Weird random crashes Marcus33 Client Support 8 25/02/2009 12:23 AM


All times are GMT. The time now is 06:18 PM.


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