SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 21/05/2019, 07:30 PM   #1
KeyOfKey
Big Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Posts: 180
Reputation: 7
Default This function is trolling me.

Seriously guys, this function is literally TROLLING me. I'll explain.

I have a vehicle system which works pretty good. Admins can do /cvehicle to create buyable vehicles. Everything's ok, vehicle(s) gets inserted correctly in database with all correct saved values.

Problem comes with this UpdateVehicleLabel. I have it on the /cvehicle command to create the textlabel of the vehicle when gets created, to inform players about price of the vehicle.

Problem is, i add it in command, i get: SERVER:Unknown Command and no successfully message "You have created a(n)" etc., but vehicles and everything gets correctly saved in db.

I remove it, everything WORKS, i don't get the unknown command and i also get the "You have created a(n)" etc. message. So 100% problem is this function.

Here it is:

pawn Code:
UpdateVehicleLabel(vid)
{
    new string[300];

    switch(VehicleData[vid][v_Owned])
    {
        case 0: //Not owned, free to purchase
        {
            format(string, sizeof(string), "Vehicle For Sale ("YELLOW"vid: %d"WHITE")\n"YELLOW"%s "WHITE"- Price: "GREEN"%s", vid, VehicleNames[vid-400], formatInt(VehicleData[vid][v_Price]));
            VehicleData[vid][v_Label] = CreateDynamic3DTextLabel(string, -1, VehicleData[vid][v_PosX], VehicleData[vid][v_PosY], VehicleData[vid][v_PosZ], VehicleData[vid][v_PosA], VehicleData[vid][v_Model], 1);
        }

        case 1: ResetVehicleLabel(vid);
    }

    if(VehicleData[vid][v_PlayerPrice])
    {
        ResetVehicleLabel(vid);

        format(string, sizeof(string), "Vehicle For Sale ("YELLOW"vid: %d"WHITE" - Owner: "YELLOW"%s)\n"YELLOW"%s "WHITE"("YELLOW"%f kilometers"WHITE") - Price: "GREEN"%s", vid, VehicleData[vid][v_Owner], VehicleNames[vid-400], VehicleData[vid][v_Mileage], formatInt(VehicleData[vid][v_PlayerPrice]));
        VehicleData[vid][v_Label] = CreateDynamic3DTextLabel(string, -1, VehicleData[vid][v_PosX], VehicleData[vid][v_PosY], VehicleData[vid][v_PosZ], VehicleData[vid][v_PosA], VehicleData[vid][v_Model], 1);
    }
    printf("Creted v_label for vdb_id: %d - vid: %d - string: %s", vid, VehicleData[vid][v_Model], string);
}

I'm using iterators to create vehicle. Here is a piece of /cvehicle code (i've removed saving parts because i think they're useless):

pawn Code:
CMD:cvehicle(playerid, params[])
{
    if(Player[playerid][AdminLevel] < 5) return ErrorMessage(playerid, COLOR_ERROR, 1);

    new car[50], price, vehid, color1, color2, Float:x, Float:y, Float:z, Float:angle, string[300], id;

    id = Iter_Free(ServerVehicles);

    if(sscanf(params, "s[50]ddd", car, price, color1, color2)) return SendUsageMessage(playerid, "/cvehicle [vehicle id/name] [price] [color 1 (255 for random)] [color 2 (255 for random)]");

    if(!isnumeric(car))
    {
        vehid = GetVehicleModelIDFromName(car);
    }
    else
    {
        vehid = strval(car);
    }

    if(!Iter_Contains(ServerVehicles, id))
    {
        Iter_Add(ServerVehicles, id);

        VehicleData[id][v_DBID] = id;

        UpdateVehicleLabel(id);

        SCMEX(playerid, 0xFFFF00FF, "You have created a(n) %s. ID: %d - Price: %s - Color 1: %d - Color 2: %d", VehicleNames[vehid-400], id, formatInt(price), color1, color2);
    }
    return 1;
}

So the free ID will be added to v_DBID (enum) which holds the "id" row on "vehicles" table.

Why this hell function bugs me everything? What's wrong? I've tried to debug it with printf but nothing is shown.
KeyOfKey is offline   Reply With Quote
Old 21/05/2019, 08:14 PM   #2
Plastikmensch
Big Clucker
 
Join Date: Aug 2016
Posts: 164
Reputation: 8
Default Re: This function is trolling me.

You try to attach the label to a modelid not vehicleid.
Code:
CreateDynamic3DTextLabel(string, -1, VehicleData[vid][v_PosX], VehicleData[vid][v_PosY], VehicleData[vid][v_PosZ], VehicleData[vid][v_PosA], VehicleData[vid][v_Model], 1);
Should be
Code:
CreateDynamic3DTextLabel(string, -1, VehicleData[vid][v_PosX], VehicleData[vid][v_PosY], VehicleData[vid][v_PosZ], VehicleData[vid][v_PosA], vid, 1);
if vid is the actual vehicleid.
(Also don't store the position in an array, store the vehicled and use GetVehiclePos, it's much more accurate)
Plastikmensch is offline   Reply With Quote
Old 21/05/2019, 08:17 PM   #3
KeyOfKey
Big Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Posts: 180
Reputation: 7
Default Re: This function is trolling me.

v_Model actually saves the vehicleid in the enum/dabase, (from 411 to 600), so my code is correct.

vid is referred to vehicle dabatase id, not samp vehicle id.
KeyOfKey is offline   Reply With Quote
Old 21/05/2019, 08:17 PM   #4
austin070
Huge Clucker
 
austin070's Avatar
 
Join Date: Aug 2010
Posts: 374
Reputation: 18
Default Re: This function is trolling me.

I'm having trouble myself figuring out what's wrong with your code -- it looks okay superficially unless I've overlooked something. Try adding a return at the end of your UpdateVehicleLabel function.
austin070 is offline   Reply With Quote
Old 21/05/2019, 08:19 PM   #5
KeyOfKey
Big Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Posts: 180
Reputation: 7
Default Re: This function is trolling me.

I added already a return, resolved nothing.
KeyOfKey is offline   Reply With Quote
Old 21/05/2019, 08:22 PM   #6
austin070
Huge Clucker
 
austin070's Avatar
 
Join Date: Aug 2010
Posts: 374
Reputation: 18
Default Re: This function is trolling me.

Quote:
Originally Posted by Plastikmensch View Post
You try to attach the label to a modelid not vehicleid.
Code:
CreateDynamic3DTextLabel(string, -1, VehicleData[vid][v_PosX], VehicleData[vid][v_PosY], VehicleData[vid][v_PosZ], VehicleData[vid][v_PosA], VehicleData[vid][v_Model], 1);
Should be
Code:
CreateDynamic3DTextLabel(string, -1, VehicleData[vid][v_PosX], VehicleData[vid][v_PosY], VehicleData[vid][v_PosZ], VehicleData[vid][v_PosA], vid, 1);
if vid is the actual vehicleid.
(Also don't store the position in an array, store the vehicled and use GetVehiclePos, it's much more accurate)
Quote:
Originally Posted by KeyOfKey View Post
v_Model actually saves the vehicleid in the enum/dabase, (from 411 to 600), so my code is correct.

vid is referred to vehicle dabatase id, not samp vehicle id.

I believe she is correct. Your explanation of v_Model is exactly what Plastikmensch was trying to tell you it shouldn't be. The server needs to know to which vehicle id to attach the label, and it appears you are telling to attach to the vehicle's model, which would technically attach it to whichever vehicle has the same server ID as the model number passing to the function.

Last edited by austin070; 21/05/2019 at 09:16 PM.
austin070 is offline   Reply With Quote
Old 21/05/2019, 08:24 PM   #7
KeyOfKey
Big Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Posts: 180
Reputation: 7
Default Re: This function is trolling me.

However i already tried his solution and still rsolved nothing. I tried this morning.
KeyOfKey is offline   Reply With Quote
Old 21/05/2019, 08:24 PM   #8
Plastikmensch
Big Clucker
 
Join Date: Aug 2016
Posts: 164
Reputation: 8
Default Re: This function is trolling me.

Quote:
Originally Posted by KeyOfKey View Post
v_Model actually saves the vehicleid in the enum/dabase, (from 411 to 600), so my code is correct.

vid is referred to vehicle dabatase id, not samp vehicle id.
Waaait, did you mean 400-611? Are you confusing the modelid and vehicleid?
modelid = value between 400-611 (type of vehicle)
vehicleid = value between 1 and 2000 (actual id of vehicle)

Why are you calling it v_Model if it's supposed to be v_ID? It's confusing.
Plastikmensch is offline   Reply With Quote
Old 21/05/2019, 08:27 PM   #9
austin070
Huge Clucker
 
austin070's Avatar
 
Join Date: Aug 2010
Posts: 374
Reputation: 18
Default Re: This function is trolling me.

Quote:
Originally Posted by KeyOfKey View Post
However i already tried his solution and still rsolved nothing. I tried this morning.
Make the change Plastikmensch suggested.

Last edited by austin070; 21/05/2019 at 09:54 PM.
austin070 is offline   Reply With Quote
Old 21/05/2019, 08:47 PM   #10
Plastikmensch
Big Clucker
 
Join Date: Aug 2016
Posts: 164
Reputation: 8
Default Re: This function is trolling me.

Quote:
Originally Posted by austin070 View Post
Make the change Plastikmensch suggested and update your UpdateVehicleLabel(id); line to UpdateVehicleLabel(car);
The car variable is the modelid again, which will not work.
I guess in the command is something like VehicleData[id][v_Model] = vehid; which is correct, if you want the modelid. But the vehicleid doesn't seem to be saved anywhere. The call is correct (as far as I can tell).

vehid should be renamed to modid, since it is the modelid not vehicleid.
The usage message should be "/cvehicle [model id/name]..." to avoid confusion.

Btw. I'm female.
Plastikmensch 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
[Map] TROLLING MAP Wreeper Maps 2 06/09/2018 08:46 AM
Trolling at its best freddy smyth Everything and Nothing 17 01/03/2013 05:25 PM
[FilterScript] Trolling FS Majed Filterscripts 34 12/10/2012 01:09 AM
Pawno trolling me CutX Scripting Help 12 01/09/2012 10:36 AM
Fl Studio 10 - Trolling :D KeeDee Everything and Nothing 0 06/03/2012 10:53 PM


All times are GMT. The time now is 01:18 AM.


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