PDA

View Full Version : Duel bugged.


ivndosos
14/02/2018, 05:05 PM
So my issue is, Is that when I go to the duel I don't get no weapons!


CMD:duel(playerid, params[])
{
new user, weap[45], weaponid = -1, str[128], str2[128];
if(sscanf(params, "us[45]", user, weap)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /duel [id/name], [weapon name]");
if(user == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) That player is not connected!");
if(user == playerid) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) You can't duel yourself!");
if(duelinfo[playerid][induel] == 1) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) You're already dueling!");
if(duelinfo[user][induel] == 1) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) That player is already dueling!");
if(invite[user] == 1) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) That player already got a duel invitation!");
if(inviter[playerid] == 1) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) You already invited someone, wait till it's rejected or accepted");
if(IsPlayerInLobby[user] == 1) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) That player is in lobby therefore he can't duel!");
if(InArena1[user] == 1) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) That player is in arena, he must quit in order to duel you!");
if(InArena2[user] == 1) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) That player is in arena, he must quit in order to duel you!");
if(StringNumeric(weap))
{
weaponid = strval(weap);
}
else
{
weaponid = strval(weap);
}
DuelSender[user] = playerid;
duelinfo[playerid][weapid] = weaponid;
duelinfo[playerid][weapname] = weap;
duelinfo[user][weapid] = weaponid;
duelinfo[user][weapname] = weap;
invite[user] = 1;
inviter[playerid] = 1;
DuelReceiver[playerid] = user;
format(str, sizeof(str), "{339933}(DUEL) You have sent a duel invitation to %s(ID:%d) (Weapon: %s)", duelinfo[user][playername], user, weap);
SendClientMessage(playerid, -1, str);
format(str2, sizeof(str2), "{339933}(DUEL) You have received a duel invitation from %s(ID:%d) (Weapon: %s)", duelinfo[playerid][playername], playerid, weap);
SendClientMessage(user, -1, str2);
return 1;
}
CMD:accept(playerid, params[])
{
if(invite[playerid] == 1)
{
new user = DuelSender[playerid];
SetTimerEx("ResetWeapons", 1000, false, "i", playerid);
RemovePlayerFromVehicle(user);
SetPlayerArmour(user, 100);
SetPlayerHealth(user, 100);
SetPlayerVirtualWorld(user, 100);
SetPlayerPos(user, -1432.3037,997.8691,1024.2102);
SetPlayerInterior(user, 15);
GivePlayerWeapon(user, duelinfo[playerid][weapid], 500);
duelinfo[user][induel] = 1;
inviter[user] = 0;
SetTimerEx("DuelWeapons1", 2000, false, "i", user);

ResetPlayerWeapons(playerid);
RemovePlayerFromVehicle(playerid);
SetPlayerArmour(playerid, 100);
SetPlayerHealth(playerid, 100);
SetPlayerVirtualWorld(playerid, 100);
SetPlayerPos(playerid, -1357.0106,998.1605,1024.0735);
SetPlayerInterior(playerid, 15);
duelinfo[playerid][induel] = 1;
SetTimerEx("DuelWeapons", 2000, false, "i", playerid);
SetTimerEx("ResetWeapons1", 1000, false, "i", playerid);
invite[playerid] = 0;
}
else return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) You didn't receive any duel requests!");
return 1;
}
forward ResetWeapons1(playerid);
public ResetWeapons1(playerid)
{
ResetPlayerWeapons(playerid);
return 1;
}

forward DuelWeapons(playerid);
public DuelWeapons(playerid)
{
GivePlayerWeapon(playerid, duelinfo[playerid][weapid], 500);
return 1;
}
forward DuelWeapons1(user);
public DuelWeapons1(user)
{
GivePlayerWeapon(user, duelinfo[user][weapid], 500);
return 1;
}

jasperschellekens
14/02/2018, 07:49 PM
Add debug messages to get an indication of the problem. It could for example have something to do with duelinfo[playerid][weapid].

duelinfo[playerid][weapid] = weaponid;
weaponid gets his info from strval(weap)
Try changing weaponid to an actual weapon id. You will have to simply test a few things to check where the problem comes from.
Debug messages will help you with this.

AdamsLT
14/02/2018, 11:16 PM
Do what Jasper said. I believe the problem might be there as well.


But I skimmed through your code. Just a heads up - your /accept command has a few flaws that you should correct.

In the user block:
You reset the weapons of the playerid instead of the user.
You give weapons to user twice (one with a timer, one with the GivePlayerWeapon function).

In the playerid block:
You reset the players weapons twice. Once with a timer and once with just the ResetPlayerWeapons function.



I'd strongly advise you to do it all in a separate function and just pass a different playerid to it since you are bound to miss something while typing the exact same code twice.

ivndosos
15/02/2018, 04:35 AM
Okay, btw.

I use this guy's filterscript. I re-wrote his whole FS so I can learn along the way because there are no tutorials on how to make a duel system.

http://forum.sa-mp.com/showthread.php?t=531402

ivndosos
15/02/2018, 05:26 AM
new WeaponInfo[][sWeaponInfo] =
{
{"Fist",1,0},
{"Brass Knuckles",1,0},
{"Golf Club",1,1},
{"Nightstick",1,1},
{"Knife",1,1},
{"Baseball Bat",1,1},
{"Shovel",1,1},
{"Pool cue",1,1},
{"Katana",1,1},
{"Chainsaw",1,1},
{"Double-ended Dildo",1,10},
{"Dildo",1,10},
{"Vibrator",1,10},
{"Silver Vibrator",1,10},
{"Flowers",1,10},
{"Cane",1,10},
{"Grenade",1,8},
{"Tear Gas",1,8},
{"Molotov Cocktail",1,8},
{"9mm Pistol",1,2},
{"Silenced 9mm",1,2},
{"Deagle",1,2},
{"Shotgun",1,3},
{"Sawnoff Shotgun",1,3},
{"Combat Shotgun",1,3},
{"Micro SMG",1,4},
{"MP5",1,4},
{"AK-47",1,5},
{"M4",1,5},
{"Tec-9",1,4},
{"Country Rifle",1,6},
{"Sniper Rifle",1,6},
{"RPG",1,7},
{"HS Rocket",1,7},
{"Flamethrower",1,7},
{"Minigun",1,7},
{"Sachel Charge",1,8},
{"Detonator",1,12},
{"Spray Can",1,9},
{"Fire Extinguisher",1,9},
{"Camera",1,9},
{"Night Vision Goggles",0,11},
{"Thermal Goggles",0,11},
{"Parachute",1,11}
};


CMD:accept(playerid, params[])
{
if(invite[playerid] == 1)
{
new user = DuelSender[playerid];
ResetPlayerWeapons(user);
RemovePlayerFromVehicle(user);
SetPlayerArmour(user, 0);
SetPlayerHealth(user, 100);
SetPlayerVirtualWorld(user, 100);
SetPlayerPos(user, 1399.3311, 2789.9409, 10.8203);
GivePlayerWeapon(user, duelinfo[playerid][weapid], 500);
duelinfo[user][induel] = 1;
inviter[user] = 0;

ResetPlayerWeapons(playerid);
RemovePlayerFromVehicle(playerid);
SetPlayerArmour(playerid, 0);
SetPlayerHealth(playerid, 100);
SetPlayerVirtualWorld(playerid, 100);
GivePlayerWeapon(playerid, duelinfo[user][weapid], 500);
SetPlayerPos(playerid, 1358.0012, 2789.6218, 10.8203);
duelinfo[playerid][induel] = 1;
invite[playerid] = 0;
}
else return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) You didn't recieve any duel request");
return 1;
}

Sew_Sumi
15/02/2018, 06:08 AM
Are you using an anti-cheat? Or anything else that would modify the way it handles weapons?

Also a good idea could be to put messages in the accept so you know it succeeded, not just by the giving of weapons.

ivndosos
15/02/2018, 06:28 AM
No I don't use any anti-cheat, However when I choose to add a weapon I can type "dadsa", and I will receive a messsage "You got a duel from ... with weapon dadsa"

I think something is wrong in the duel command itself and the new WeaponInfo.

Sew_Sumi
15/02/2018, 06:41 AM
No I don't use any anti-cheat, However when I choose to add a weapon I can type "dadsa", and I will receive a messsage "You got a duel from ... with weapon dadsa"

I think something is wrong in the duel command itself and the new WeaponInfo.

Indeed, return the variables using printf, or SendClientMessage more often (All stages of the commands for debug as such). The accept command also looks confusing for the amount of work it does.

ivndosos
15/02/2018, 06:45 AM
How do I printf it exactly? I never really used it so I don't know.

Kane
15/02/2018, 06:53 AM
if(StringNumeric(weap))
{
weaponid = strval(weap);
}
else
{
weaponid = strval(weap);
}

?

ivndosos
15/02/2018, 06:57 AM
I've mentioned above that I re-wrote the FS so I can learn along the way, I've linked it up above you can have a look, Is the FS itself bugged?

PepsiCola23
15/02/2018, 08:20 AM
Test the fs itself separately and tell us if the problem persists

Sew_Sumi
15/02/2018, 09:21 AM
^^ As they said... Test the FS, non-modified, and if it works, then your modified code is at fault. If it doesn't work, then it probably wasn't able to run in the first instance.