SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 13/02/2019, 11:22 AM   #11
ComDuck
Big Clucker
 
ComDuck's Avatar
 
Join Date: Feb 2019
Posts: 80
Reputation: 12
Default Re: GetWeaponPickupCreatePos

Quote:
Originally Posted by TheToretto View Post
pawn Code:
#include <a_samp>
#include <streamer>

CreateWeaponPickup(weaponid, Float:x, Float:y, Float:z)
{
    weaponid = GetWeaponPickupID(weaponid);
    CreateDynamicPickup(weaponid, 1, x, y, z, -1, -1, -1, STREAMER_PICKUP_SD);
    return 1;
}

GetWeaponPickupID(weaponid)
{
    switch(weaponid)
    {    
        case 1: return 331;
        case 2: return 333;
        case 3: return 334;
        case 4: return 335;
        case 5: return 336;
        case 6: return 337;
        case 7: return 338;
        case 8: return 339;
        case 9: return 341;
        case 10: return 321;
        case 11: return 322;
        case 12: return 323;
        case 13: return 324;
        case 14: return 325;
        case 15: return 326;
        case 16: return 342;
        case 17: return 343;
        case 18: return 344;
        case 22: return 346;
        case 23: return 347;
        case 24: return 348;
        case 25: return 349;
        case 26: return 350;
        case 27: return 351;
        case 28: return 352;
        case 29: return 353;
        case 30: return 355;
        case 31: return 356;
        case 32: return 372;
        case 33: return 357;
        case 34: return 358;
        case 35: return 359;
        case 36: return 360;
        case 37: return 361;
        case 38: return 362;
        case 39: return 363;
        case 40: return 364;
        case 41: return 365;
        case 42: return 366;
        case 43: return 367;
        case 44: return 368;
        case 45: return 369;
        case 46: return 371;
        default: return 1239;
    }
    return 1;
}
It's better to use an array to store the IDs instead. Either define a macro that points to the array or access the array content directly.
ComDuck is offline   Reply With Quote
Old 13/02/2019, 12:46 PM   #12
TheToretto
Huge Clucker
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 411
Reputation: 33
Default Re: GetWeaponPickupCreatePos

Quote:
Originally Posted by ComDuck View Post
It's better to use an array to store the IDs instead. Either define a macro that points to the array or access the array content directly.
Why not.

Code:
new WeaponsObject[] = {
    1239,331,333,334,335,336,337,338,
    339,341,321,322,323,324,325,326,
    342,343,344,1239,1239,1239,346,
    347,348,349,350,351,352,353,355,
    356,372,357,358,359,360,361,362,
    363,364,365,366,367,368,369,371
};

#define ReturnWeapon(%0) WeaponsObject[%0]

CreateWeaponPickup(weaponid, Float:x, Float:y, Float:z)
{
    weaponid = ReturnWeapon(weaponid);
    CreateDynamicPickup(weaponid, 1, x, y, z, -1, -1, -1, STREAMER_PICKUP_SD);
    return 1;
}
Notice some invalid weapons ID's values were replaced by 1239.
__________________






Toretto#9902

Rest in peace grandpa, 03 November 2018
TheToretto is online now   Reply With Quote
Old 13/02/2019, 09:08 PM   #13
EmpireSk
Huge Clucker
 
EmpireSk's Avatar
 
Join Date: Jul 2013
Location: Slovakia
Posts: 335
Reputation: 10
Default Re: GetWeaponPickupCreatePos

My code can not be fixed....? Because when I erase a symbol "&" so error is not, but servers will not show weapons
__________________
EmpireSk is offline   Reply With Quote
Old 16/02/2019, 12:25 AM   #14
EmpireSk
Huge Clucker
 
EmpireSk's Avatar
 
Join Date: Jul 2013
Location: Slovakia
Posts: 335
Reputation: 10
Default Re: GetWeaponPickupCreatePos

Hmmm.... Help me boys
__________________
EmpireSk is offline   Reply With Quote
Old 16/02/2019, 02:21 PM   #15
TheToretto
Huge Clucker
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 411
Reputation: 33
Default Re: GetWeaponPickupCreatePos

Quote:
Originally Posted by EmpireSk View Post
My code can not be fixed....? Because when I erase a symbol "&" so error is not, but servers will not show weapons
Your code means nothing, the "number" argument is unknown, what is its job? And I wrote you a function up. Use it instead.

Quote:
Originally Posted by TheToretto View Post
Why not.

Code:
new WeaponsObject[] = {
    1239,331,333,334,335,336,337,338,
    339,341,321,322,323,324,325,326,
    342,343,344,1239,1239,1239,346,
    347,348,349,350,351,352,353,355,
    356,372,357,358,359,360,361,362,
    363,364,365,366,367,368,369,371
};

#define ReturnWeapon(%0) WeaponsObject[%0]

CreateWeaponPickup(weaponid, Float:x, Float:y, Float:z)
{
    weaponid = ReturnWeapon(weaponid);
    CreateDynamicPickup(weaponid, 1, x, y, z, -1, -1, -1, STREAMER_PICKUP_SD);
    return 1;
}
Notice some invalid weapons ID's values were replaced by 1239.
__________________






Toretto#9902

Rest in peace grandpa, 03 November 2018
TheToretto is online now   Reply With Quote
Old 17/02/2019, 12:35 PM   #16
EmpireSk
Huge Clucker
 
EmpireSk's Avatar
 
Join Date: Jul 2013
Location: Slovakia
Posts: 335
Reputation: 10
Default Re: GetWeaponPickupCreatePos

And will it work ...? is it instead?
__________________
EmpireSk is offline   Reply With Quote
Old 17/02/2019, 12:46 PM   #17
J0sh...
High-roller
 
J0sh...'s Avatar
 
Join Date: Aug 2014
Location: Hamburger
Posts: 1,379
Reputation: 441
Default Re: GetWeaponPickupCreatePos

What's even the point of that macro at all? There's no need for it and heck, its bad practice.
__________________
🍔🍔🍔🍔🍔🍔🍔🍔🍔🍔🍔🍔
Yes I know my name has 3 dots.
Thanks for noticing, it was meant to signify a pause in the personal message asking to be named J0sh but they got included.
J0sh... is offline   Reply With Quote
Old 17/02/2019, 01:12 PM   #18
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,710
Reputation: 3226
Default Re: GetWeaponPickupCreatePos

Quote:
Originally Posted by TheToretto View Post

Notice some invalid weapons IDís values were replaced by 1239.
Why?
Y_Less is online now   Reply With Quote
Old 17/02/2019, 01:48 PM   #19
TheToretto
Huge Clucker
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 411
Reputation: 33
Default Re: GetWeaponPickupCreatePos

Quote:
Originally Posted by EmpireSk View Post
And will it work ...? is it instead?
Try it...

Quote:
Originally Posted by J0sh... View Post
What's even the point of that macro at all? There's no need for it and heck, its bad practice.
Yeah it's just to make it more readable without having to name the variable, it is optional and useless.

Quote:
Originally Posted by Y_Less View Post
Why?
Because in his last switch statement it had:

Code:
default: return 1239;
So I replaced all the invalid weapons slots by that, which are between:

Code:
case 18: return 344;
case 22: return 346;
So 19-20-21 were invalid.
__________________






Toretto#9902

Rest in peace grandpa, 03 November 2018
TheToretto is online now   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



All times are GMT. The time now is 10:47 AM.


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