Going from racename to raceid
#1

Hello

I made a race system a while ago and it has this command to start or join races: /joinrace <id>
However I wanna change it to: /joinrace <racename>

So here's what I tried doing:

pawn Код:
CMD:joinrace(playerid, params[])
{
    JoinRace(playerid, raceid);*/
   
    new name[56], raceid;
    if(PInfo[playerid][VortexJump] == 1 ) return SendClientMessage(playerid,COLOR_RED,"You cannot use this command here, finish your jump please");
    if(sscanf(params,"s[56]",name)) return SendClientMessage(playerid, COLOR_RED, "Invalid race name");
   
    for(new x = 0;x<currentraceslot; x++)
    {
        if(!strcmp(RaceInfo[x][racename], name, false))
        {
            raceid = x;
        }
        //break;
    }
   
    if(raceid == 0) return SendClientMessage(playerid, COLOR_RED, "Invalid race name");
    if(RaceInfo[raceid][racejoinable] == false && RaceInfo[raceid][racerunning] == false && PInfo[playerid][Racing] == -1) OpenRace(raceid);
    JoinRace(playerid, raceid);
   
    SendClientMessage(playerid, COLOR_GREEN, "racename called");
   


    return 1;
}
So I loop through all the races and then compare their name with the params, however for some reason for every name I type after /joinrace it always calls the race with raceid 0....

Do you know what could be wrong?
Thanks in advance
Reply
#2

Are you typing in the exact name of the race's name? With the exact same cases? Your strcmp is checking to see if the races name is the exact same string as the name of the race you type in after /joinrace.
EG: Races name is 'firsttoLosSantos'; and you type in 'firsttoLossantos'; it will return false.

Maybe try this. Also; add in some debuggers so you know whats going wrong.
pawn Код:
CMD:joinrace(playerid, params[])
{
    JoinRace(playerid, raceid);*/
   
    new name[56], raceid;
    if(PInfo[playerid][VortexJump] == 1 ) return SendClientMessage(playerid,COLOR_RED,"You cannot use this command here, finish your jump please");
    if(sscanf(params,"s[56]",name)) return SendClientMessage(playerid, COLOR_RED, "Invalid race name");
   
    for(new x = 0;x<currentraceslot; x++)
    {
        if(!strcmp(RaceInfo[x][racename], name, true)) //changed to true so it doesn't compare capital letters; etc.
        {
            raceid = x;
        }
        //break;
    }
   
    if(raceid == 0) return SendClientMessage(playerid, COLOR_RED, "Invalid race name");
    if(RaceInfo[raceid][racejoinable] == false && RaceInfo[raceid][racerunning] == false && PInfo[playerid][Racing] == -1) OpenRace(raceid);
    JoinRace(playerid, raceid);
   
    SendClientMessage(playerid, COLOR_GREEN, "racename called");
   


    return 1;
}
Reply
#3

Give a try!
pawn Код:
CMD:joinrace(playerid, params[])
{
    if(PInfo[playerid][VortexJump] == 1 ) return SendClientMessage(playerid,COLOR_RED,"You cannot use this command here, finish your jump please");
    if(isnull(params)) return SendClientMessage(playerid, COLOR_RED, "/joinrace <race name>");
    new raceid = GetRaceidFromName( params );
    if(raceid != -1)
    {
        if(raceid == 0) return SendClientMessage(playerid, COLOR_RED, "Invalid race name");
        if(RaceInfo[raceid][racejoinable] == false && RaceInfo[raceid][racerunning] == false && PInfo[playerid][Racing] == -1) OpenRace(raceid);
        JoinRace(playerid, raceid);

        SendClientMessage(playerid, COLOR_GREEN, "racename called");
    }
    else SendClientMessage(playerid, COLOR_RED, "Invalid race name");
    return 1;
}

stock GetRaceidFromName( race_name[ ] )
{
    if( !strlen( race_name ) ) return -1;
    for( new r = 0; r < currentraceslot; r++ ) if( !strcmp( RaceInfo[ r ][ racename ], race_name, false ) ) return r;
    return -1;
}
Reply
#4

@first response

Omg it worked...

I feel very stupid for asking now...
Anyways thanks and rep+

Konstant: yours worked too, thanks
Reply
#5

Np
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)